![](/img/trans.png)
[英]Google fit API - personal info - What is the units for height and weight and how i can get the gender and the birthday
[英]How exactly can I get friends profile info like birthday,gender etc using google plus API?
有人可以向我解釋一下,無論在最壞的情況還是最好的情況下,我都可以從google plus的android api中獲得哪些朋友信息。某些我無法從google文檔中找到答案。
我正在使用以下具有范圍和權限的代碼:-
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN).addScope(Plus.SCOPE_PLUS_PROFILE)
.addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
檢索我正在打電話的人的信息
Plus.PeopleApi.loadVisible(mGoogleApiClient, null)
.setResultCallback(this);
現在有什么Google API可用於獲取用戶的個人資料信息以及在什么程度上使用?
在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();
}
}
試試這個,您可以使用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)
{}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.