androidgoogle-signingoogle-profiles-api

GoogleSignInAccount getPhotoUrl() return null


Trying to get photo from signed in profile. But always return null. Name and email return values, trouble only with photo.

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestProfile()
            .requestEmail()
            .build();
mGoogleApiClient = new GoogleApiClient.Builder(StartActivity.this)
            .enableAutoManage(StartActivity.this, StartActivity.this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)   
            .build();
acct = gResult.getSignInAccount();
String name = acct.getDisplayName(); //okay, value != null
String email = acct.getEmail(); //okay, value != null
Uri photoUri = acct.getPhotoUrl() //not okay, value == null

Why does it happen so? Account signed, email and name got, but photo always fail.


Solution

  • According to Google's documentation - GoogleSignInAccount

    public Uri getPhotoUrl ()

    Gets the photo url of the signed in user.

    Returns

    photo url for the Google account. Only non-null if requestProfile() is configured and user does have a Google+ profile picture.

    Please check if your Google account has had Google+ profile picture or not.

    P/S: sometimes, if Google+ profile picture has been created already but after the time you add Google account in your device, perhaps you need to delete that existing Google account from your device, then re-add.