android – GoogleSignInAccount getPhotoUrl()返回null

前端之家收集整理的这篇文章主要介绍了android – GoogleSignInAccount getPhotoUrl()返回null前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
尝试从登录配置文件获取照片.但总是返回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帐户,然后重新添加.

原文链接:https://www.f2er.com/android/312271.html

猜你在找的Android相关文章