问题描述
我正在开发一款应用,此应用有一项功能,需要Google帐户的个人资料ID。我可以使用Google People API获取数据:
I'm working on an App and this app has a feature, which need profile ID of Google Account. I can get data using Google People API by using code:
GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
// The serverClientId is an OAuth 2.0 web client ID
.requestServerAuthCode(getString(R.string.googleWebClientId))
.requestEmail()
.requestScopes(new Scope(Scopes.PLUS_LOGIN),
new Scope(PeopleScopes.CONTACTS_READONLY),
new Scope(PeopleScopes.USER_EMAILS_READ),
new Scope(PeopleScopes.USERINFO_EMAIL),
new Scope(PeopleScopes.USER_PHONENUMBERS_READ))
.build();
// To connect with Google Play Services and Sign In
mGoogleApiClient = new GoogleApiClient.Builder(this).
enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Toast.makeText(AddContactUserToLeaderboardActivity.this, "Your account doesnot exists", Toast.LENGTH_LONG).show();
}
}).addApi(Auth.GOOGLE_SIGN_IN_API, signInOptions).
build();
People peopleService = setUp(AddContactUserToLeaderboardActivity.this, params[0]);
ListConnectionsResponse response = peopleService.people().connections()
.list("people/me")
// This line's really important! Here's why:
// http://stackoverflow.com/questions/35604406/retrieving-information-about-a-contact-with-google-people-api-java
.setRequestMaskIncludeField("person.names,person.emailAddresses,person.phoneNumbers")
.execute();
List<Person> connections = response.getConnections();
Log.e(TAG, "response: " + ((GenericJson) response).toString());
但是回复没有配置文件ID,它只有这样的联系人ID:
But the response has no Profile ID, it just has Contact ID like that:
{"connections":[{"etag":"%EgQBAgkL","names":[{"displayName":"A","givenName":"B","metadata":{"primary":true,"source":{"id":"5744b9050dfsfa281b","type":"CONTACT"}},...
我是否缺少任何字段在此行中包含Google个人资料ID? setRequestMaskIncludeField(person.names, person.emailAddresses,person.phoneNumbers)
am I missing any field to have Google Profile ID in this line?setRequestMaskIncludeField("person.names,person.emailAddresses,person.phoneNumbers")
或任何想法从People API Google获取个人资料ID?
请帮助我。
or any idea to get Profile ID from People API Google?Help me please.
推荐答案
我找到了我的解决方案。它只是ListConnectionsResponse赋值中的一个setPageSize设置属性。完全地,赋值如下所示:
I found my solution. It 's just a "setPageSize" setting property in ListConnectionsResponse assignment. Fully, assignment likes that:
ListConnectionsResponse response = peopleService.people().connections()
.list("people/me")
.setPageSize(1200)
.setRequestMaskIncludeField("person.names,person.emailAddresses,person.phoneNumbers")
.execute();
这篇关于如何在Android中使用Google People API获取Connections的配置文件ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!