小编Kot*_*tsu的帖子

Plus.PeopleApi.getCurrentPerson()返回null而不再返回

我搜索了很多但仍然没有得到解决方案.Plus.PeopleApi.getCurrentPerson()总是返回null.我得到了调试SHA1并释放了SHA1.它们都作为具有正确包名的OAuth 2.0客户端ID添加到控制台.(遗憾的是,我无法发布图片)这是我的GoogleApiClient:

    private GoogleApiClient buildGoogleApiClient() {
    return new GoogleApiClient.Builder(getContext())
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(new Scope(Scopes.PROFILE))
            .addScope(new Scope(Scopes.PLUS_LOGIN))
            .build();
}
Run Code Online (Sandbox Code Playgroud)

很简单.我从Fragment的onCreateView()中调用它.然后我想找到当前的人:

@Override
public void onConnected(Bundle bundle) {
    Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(this);

    if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
        Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
        String personName = currentPerson.getDisplayName();
        String personGooglePlusProfile = currentPerson.getUrl();
    }
Run Code Online (Sandbox Code Playgroud)

并且总是空的.mGoogleApiClient工作正常,它连接,它不是null,但仍然.在控制台 - >启用了Apis Google+ API,但"使用情况"标签中没有任何请求.

我尝试了所有可以找到的解决方案而没有任何帮助.我用geny模拟器运行应用程序.拜托,帮帮我,给我任何想法.

补充:这是我几乎完整的Fragment类:

    public class AuthorizationFragment2 extends Fragment implements
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,
        View.OnClickListener,
        ResultCallback {
    private static final String KEY_IS_RESOLVING = "is_resolving";
    private static final String KEY_SHOULD_RESOLVE = "should_resolve";
    /* Request code …
Run Code Online (Sandbox Code Playgroud)

android google-api

2
推荐指数
1
解决办法
3264
查看次数

标签 统计

android ×1

google-api ×1