我正在尝试获取 Google+ 用户的基本信息以登录我的应用。
我可以连接并获取帐户名:
String email = mPlusClient.getAccountName(); // This works, gives me the email
然后我尝试通过以下方式获取更多信息:
mPlusClient.loadVisiblePeople(new OnPeopleLoadedListener() {
@Override
public void onPeopleLoaded(ConnectionResult status,
PersonBuffer personBuffer, String nextPageToken) {
Log.i("", "persons loaded result = " + status.toString()
+ ", personsCount = " + personBuffer.getCount()
+ ", token = " + nextPageToken);
if (status.isSuccess()) {
Iterator<Person> itP = personBuffer.iterator();
while (itP.hasNext()) {
Person person = itP.next();
Toast.makeText(getApplicationContext(), person.getNickname(), 5).show();
}
}
}
}, null);
我可以获取好友信息
persons loaded result = ConnectionResult{statusCode=SUCCESS, resolution=null}, personsCount = 15, token = null
但是如果我找不到如何获取个人信息...
当我尝试时:
Person p = mPlusClient.getCurrentPerson();
p 为空,
当我尝试时:
mPlusClient.loadPerson(this, "me");
无法识别 loadPerson
所以我不知道该怎么做......
如有任何帮助,我们将不胜感激!
最佳答案
你可以试试下面的代码来获取当前用户的个人资料信息:
mGoogleApiClient = new GoogleApiClient.Builder(MainActivity.this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
if(mGoogleApiClient != null && mGoogleApiClient.isConnected()){
if(Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null){
Person mCurrentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
String displayName = mCurrentPerson.getDisplayName();
int mUserIdOfCurrentUser = mCurrentPerson.getId();
Log.d(Constants.LOG_TAG_LOAD_VISIBLE_PEOPLE, "DisplayName: "+displayName);
Log.d(Constants.LOG_TAG_LOAD_VISIBLE_PEOPLE,"Id: "+ mCurrentPerson.getId());
Log.d(Constants.LOG_TAG_LOAD_VISIBLE_PEOPLE,"Image: "+mCurrentPerson.getImage().getUrl());
Log.d(Constants.LOG_TAG_LOAD_VISIBLE_PEOPLE,"List of Urls: "+mCurrentPerson.getUrls());
Log.d(Constants.LOG_TAG_LOAD_VISIBLE_PEOPLE,"Current Url: "+mCurrentPerson.getUrl());
Log.d(Constants.LOG_TAG_LOAD_VISIBLE_PEOPLE,"Cover: "+mCurrentPerson.getCover());
Log.d(Constants.LOG_TAG_LOAD_VISIBLE_PEOPLE,"Object type: "+mCurrentPerson.getObjectType());
Log.d(Constants.LOG_TAG_LOAD_VISIBLE_PEOPLE,"User Id : "+mUserIdOfCurrentUser);
}
关于android - 使用 Google +/PlusClient 获取个人信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25903088/