How to check if Google user image is default or uploaded?

How do I check if a userโ€™s image is uploaded to Google by default?

Note When you get user details from the API.

Google User's Default Image

+6
source share
5 answers

people.get includes the isDefault value in the image object. For instance. if you try it for +Google you will get:

 "image": { "url": "https://lh4.googleusercontent.com/-v0soe-ievYE/AAAAAAAAAAI/AAAAAAACyas/yR1_yhwBcBA/photo.jpg?sz=50", "isDefault": false } 
+6
source

All profile photos have the following URL by default:

 https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg 

You can simply compare the string equality of the profile image with the given one.

+8
source

people.get no longer has isDefault as a property. https://developers.google.com/+/web/api/rest/latest/people#resource

+6
source

in ruby โ€‹โ€‹with app and omniauth-google-oauth2

in your devise.rb

 config.omniauth :google_oauth2 (Other options....), skip_image_info: false 

then in your user.rb / other place:

 def self.parse_auth_image(auth) if auth.provider == "google_oauth2" return nil if auth.dig("extra", "raw_info", "image", "isDefault") end auth.info.image end 
0
source

The best way to do this in FULL DETAILS:

 require 'open-uri' 

Default Image:

 default = "https://lh3.googleusercontent.com/- XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg" 

Image to check:

 image_to_check = "https://lh3.googleusercontent.com/- uh4wK1JDtCI/AAAAAAAAAAI/AAAAAAAAAAA/huieBSbV4zg/s64- c/100695019739939096169.jpg" 

Comparison check

 blob_for_default_image = open(default).read blob_for_image_to_check = open(image_to_check).read 

Then you compare 2 drops of the image:

 blob_for_default_image == blob_for_image_to_check 
0
source

Source: https://habr.com/ru/post/1209888/


All Articles