Plus.PeopleApi.getCurrentPerson返回null

时间:2014-11-28 15:17:28

标签: android google-plus social-networking google-signin

我目前正在使用我的应用中的Google Plus登录功能。

我创建了GoogleApiClient构建器,如下所示

Plus.PlusOptions options = new Plus.PlusOptions.Builder()
            .addActivityTypes("http://schemas.google.com/AddActivity")
            .build();

    myGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            // .addApi(Plus.API, Plus.PlusOptions.builder().build())
            .addApi(Plus.API, options)
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .addScope(Plus.SCOPE_PLUS_PROFILE).build();

和onConnected方法

@Override
public void onConnected(Bundle arg0) {
    // TODO Auto-generated method stub

    plusUtilities.ShowToast("Login successful");

    updateGPbutton();
    // hide progress DiaLog
    plusUtilities.DissmissPD();
    // it has deprecated
    // plusUtilities.ShowToast("Login to Google+ with " +
    // mPlusClient.getAccountName().toString());

    // upgraded class
    plusUtilities.ShowToast("Login to Google+ with "
            + Plus.AccountApi.getAccountName(myGoogleApiClient).toString());

    // deprecated
    // mPlusClient.loadPeople(this, "me");

    Plus.PeopleApi.load(myGoogleApiClient, "me");
    // plusUtilities.ShowPD("Fetching user data... ");

    // upgraded and call fetch_user_details method here instead of calling
    // in onPersonLoad() override method
    Log.d("Googleplusclient",
            "" + Plus.PeopleApi.getCurrentPerson(myGoogleApiClient));
    Plus.PeopleApi.loadVisible(myGoogleApiClient, null).setResultCallback(this);

    if (Plus.PeopleApi.getCurrentPerson(myGoogleApiClient) != null) {
        Person currentPerson = Plus.PeopleApi
                .getCurrentPerson(myGoogleApiClient);
        fetch_User_Details(currentPerson);
    }

}

以下方法返回null

Plus.PeopleApi.getCurrentPerson(myGoogleApiClient)

我按照the link寻求解决方案。 然后我也跟着这个developer link。 直到我得到零值。

如何解决这个问题?

1 个答案:

答案 0 :(得分:12)

嗯,你的DEBUG sha1签名与你的customkey.keystore sha1签名不同!!!! 所以你应该找到你的调试sha1签名,并在谷歌控制台ASWELL上的API凭据上创建该密钥! :D这有效并修复它相信我,检查你的api控制台,我打赌你的api请求是0?