4

I am supposed to display an default image set by my app, in case no profile image has been set by the user. For which i need to detect whether user has set any profile image or not in his google account.

Now, upon accessing profile image for a user who has not set any image yet, api is returning default profile image set by google. Also, hasImage property resulted to be of no use, as it always returns true, even for this case.

enter image description here

Following is the API, which i used to access the profileImage
GoogleSignIn (3.0.0)

GIDProfileData->hasImage : "Whether or not the user has profile image"
GIDProfileData->imageURLWithDimension : "Gets the user's profile image URL for the given dimension in pixels for each side of the square"

link to Documentation page

Here's the snippet for accessing the profile image :

if([GIDSignIn sharedInstance].currentUser.profile.hasImage) {

        NSUInteger imgSize = usrImgV.frame.size.height * 2;
        NSURL *imgUrl = [[GIDSignIn sharedInstance].currentUser.profile imageURLWithDimension:imgSize];
        [usrImgV setImageWithURL:imgUrl placeholderImage:placeholderImg];

    }



Last resort for this seems to compare the image, that will also break in case default image changes.

Amit
  • 1,128
  • 6
  • 15
  • 29
  • Gmail has this default image if user has not set his profile picture. So, "hasImage" attribute will always return true. – Aneeq Anwar Mar 29 '16 at 08:14
  • @AneeqAnwar, then what is the point of having this property if it is supposed return a constant value. Also, then there is no way to detect if user has chosen a profile image or not. – Amit Mar 29 '16 at 09:25
  • For google+ the image url has a property isDefault, if set to false..then you will be getting current profile picture of user. Maybe you should try fetching image url for google sign in also. – Akash KR Apr 06 '16 at 16:42
  • 1
    I got ur answer. Create a NSData for the default image returned by google and compare it with the profile picture. If it is true then return default image, if false , you will have your current profile picture. – Akash KR Apr 07 '16 at 08:15
  • @AkashKR, what you are suggesting is sort of image comparison. I want to stick to that as last option, as it has a dependency on the fact that default image is going to remain same. "isDefault" would had been best choice, but i don't thing they are serving it any more in their google API. – Amit Apr 07 '16 at 09:09
  • @Amit, so i guess no bounty then – Akash KR Apr 07 '16 at 10:01
  • @AkashKR, i am hoping there should some answer as it seems to be very common use case scenario. – Amit Apr 07 '16 at 10:17
  • @Amit, ok look for your desired answer. But you've asked for the answer irrespective of common use case scenario. So, if you fail bounty should be mine. – Akash KR Apr 07 '16 at 11:02
  • 1
    @Amit, here is a same questions as like your, Here is the link- http://stackoverflow.com/questions/27649696/how-to-check-whether-google-users-image-is-default-or-uploaded Visit this link may be it should be helpful to you. – Jigar Tarsariya Apr 08 '16 at 07:03
  • @JigarTarsariya, that is valid for google plus api. I don't think that it applies also in case of google API. – Amit Apr 08 '16 at 09:15
  • I also want to distinguish between the default image and profile pic set by user....Did you find any answer for this. I cannot use google plus login. I want to implement this feature using Google login only...Kindly guide me ... – Sunita Apr 29 '16 at 06:49
  • Having the same issue! – Jeremiah Mar 14 '17 at 01:43
  • @Amit have you ever found answer for same? – deen Apr 01 '22 at 08:29

0 Answers0