问题
I was using Google Sign in API to request user profile, likes user display name, avatar photo. I got null value GoogleSignInAccount.getPhotoUrl(), got value GoogleSignInAccount.getDisplayName().
Gmail account ok, but private account is not. private account is linked to Google gmail, it can see the picture in my Gmail account and Google Play store app, Google plus too. but why I got null value with using Google Sign In account API.
GoogleSignInOptions.Builder builder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail();
builder.setAccountName(userAcc);
GoogleSignInOptions gso = builder.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, 0, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
private void handleSignInResult(final GoogleSignInResult result) {
if (result.isSuccess()) {
if (getBaseContext() == null) {
return;
}
GoogleSignInAccount acct = result.getSignInAccount();
final String email = acct.getEmail();
final String displayName = acct.getDisplayName();
final Uri uri = acct.getPhotoUrl();
String sUri = null;
if (uri != null) {
sUri = uri.toString();
}
System.out.println("GoogleSignInAccount: getPhotoUrl: " + sUri);
回答1:
Use https://www.googleapis.com/plus/v1/people/USER_ID?fields=image&key=AIzaSyBz2jGjZl0VGkllxYYKRHPuuAX_oMxdyVQ
, return json containing avatar
来源:https://stackoverflow.com/questions/36760049/google-sign-in-api-get-photo-uri-is-null