有人可以向我解释一下,在最糟糕和最好的情况下,我可以通过google plus和android api获得什么样的朋友信息。有些我怎么也无法从谷歌文档中找到它。
我正在使用具有范围和权限的以下代码: -
<select multiple="multiple" style="width:250px" name="listOfFruits" id="listOfFruits" disabled="disabled" class="whiteBackground">
检索我正在调用的人员信息
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN).addScope(Plus.SCOPE_PLUS_PROFILE)
.addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
现在有没有google api我可以用它来获取用户的个人资料信息以及到什么程度?
答案 0 :(得分:0)
在onConnected方法中调用方法getProfileInformation(),在这个方法中你可以得到所有的个人资料信息
@Override
public void onConnected(Bundle bundle) {
mSignInClicked = false;
Toast.makeText(this, "User is connected!", Toast.LENGTH_LONG).show();
// Get user's information
getProfileInformation();
/**
* Fetching user's information name, email, profile pic
* */
private void getProfileInformation() {
try {
if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
Person currentPerson = Plus.PeopleApi
.getCurrentPerson(mGoogleApiClient);
String personName = currentPerson.getDisplayName();
String personPhotoUrl = currentPerson.getImage().getUrl();
String personGooglePlusProfile = currentPerson.getUrl();
String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
**currentPerson.getBirthday();
currentPerson.getGender();
currentPerson.getRelationshipStatus();**
} else {
Toast.makeText(getApplicationContext(),
"Person information is null", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
答案 1 :(得分:0)
试试这个,您可以通过personBuffer.get(i)获取任何信息:
private static final int PROFILE_PIC_SIZE = 400;
public void getProfileInformation() {
try {
Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(new ResultCallback<People.LoadPeopleResult>() {
@Override
public void onResult(People.LoadPeopleResult loadPeopleResult) {
if (loadPeopleResult.getStatus().getStatusCode() == CommonStatusCodes.SUCCESS) {
PersonBuffer personBuffer = loadPeopleResult.getPersonBuffer();
try {
int count = personBuffer.getCount();
for (int i = 0; i < count; i++) {
String name = personBuffer.get(i).getDisplayName();
String nickName = personBuffer.get(i).getNickname();
String gender = personBuffer.get(i).getGender();
String urlPhoto = personBuffer.get(i).getImage().getUrl().substring(0,
personBuffer.get(i).getImage().getUrl().length() - 2)
+ PROFILE_PIC_SIZE;
//And other things...
if(personBuffer.get(i).getPlacesLived() != null || personBuffer.get(i).hasPlacesLived()) {
for (Person.PlacesLived place : personBuffer.get(i).getPlacesLived()) {
if (place.isPrimary()) {
String placesLived = place.getValue();
}
}
}
}
} finally {
personBuffer.close();
}
} else {
}
}
});
}catch(Exception e)
{}
}