Google登录API-获取照片Uri为空 [英] Google Sign in API - get photo Uri is null

查看:127
本文介绍了Google登录API-获取照片Uri为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当时使用Google登录API请求用户个人资料,例如用户显示名称,头像照片.我得到 null 值GoogleSignInAccount.getPhotoUrl(),得到了GoogleSignInAccount.getDisplayName().

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帐户,但不能使用私人帐户.私人帐户已链接到Google gmail,因此可以在我的Gmail帐户和Google Play商店应用(Google plus)中看到图片.但是为什么我通过使用Google登录帐户API却得到了空值.

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);

推荐答案

使用https://www.googleapis.com/plus/v1/people/USER_ID?fields=image&key=AIzaSyBz2jGjZl0VGkllxYYKRHPuuAX_oMxdyVQ,返回包含头像的json

Use https://www.googleapis.com/plus/v1/people/USER_ID?fields=image&key=AIzaSyBz2jGjZl0VGkllxYYKRHPuuAX_oMxdyVQ , return json containing avatar

这篇关于Google登录API-获取照片Uri为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆