Google People API与GoogleApiClient一起使用(列出所有朋友)

时间:2016-11-25 08:07:46

标签: android google-api google-api-client google-people

// Setup
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
    .requestScopes(new Scope(PeopleScopes.CONTACTS_READONLY))
    .build();

mGoogleClient = new GoogleApiClient.Builder(context)
    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .build();

// Login
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleClient);
mActivity.startActivityForResult(signInIntent, REQUEST_CODE_LOGIN);

// Restore Login
// mGoogleClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL);

这是我处理登录结果的方式:

public void onActivityResult(int requestCode, int responseCode, Intent data)
{
    if (mGoogleClient != null && requestCode == REQUEST_CODE_LOGIN)
    {
        mLoginResult = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (mLoginResult.isSuccess())
        {
            getAllContacts();
        }
    }
}

这就是问题,我该如何转换这种旧感冒?我想继续使用GoogleApiClient

private void getAllContacts()
{
    // 1) Own Profil
    Person pMe = Plus.PeopleApi.getCurrentPerson(mGoogleClient);

    // 2) Friends
    PendingResult<People.LoadPeopleResult> result = Plus.PeopleApi.loadVisible(mGoogleClient, People.OrderBy.BEST, null);
    People.LoadPeopleResult loadPeopleResult = result.await();
    if (loadPeopleResult.getStatus().isSuccess())
    {
        PersonBuffer people = loadPeopleResult.getPersonBuffer();
        for (Person p : people)
        {
            // ...
        }
        people.close();
    }
}

我想要什么

我想在GoogleApiClient的帮助下列出有人关注的所有人(或者有人在他的任何一个圈子中)。有谁知道如何实现这个目标?

0 个答案:

没有答案