尝试从登录的配置文件中获取照片.但总是返回null.名称和电子邮件返回值,只有照片才有麻烦.
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
解决方法
根据
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.
请检查您的Google帐户是否拥有Google个人资料图片.
P / S:有时,如果Google个人资料照片已经创建,但在您的设备中添加Google帐户后,您可能需要从设备中删除现有的Google帐户,然后重新添加.