2013-08-29 35 views
1

我正在做一些與Android/google_play_service庫和PlusClient的工作。具體來說,我只是使用我的聯繫人姓名填寫ListView,並在他們的G +個人資料頁面上提供一些基本信息。Android/PlusClient:loadPeople返回不完整的PersonBuffer對象在onPeopleLoaded

爲了加載列表,我進行如下:

// Create my PlusClient 
activityContext = getActivity().getApplicationContext(); 
client = new PlusClient.Builder(activityContext, this, this) 
      .setScopes(Scopes.PLUS_PROFILE, Scopes.PLUS_LOGIN) 
      .build(); 

// Load the people 
// this = the current activity 
client.loadPeople(this, Person.Collection.VISIBLE); 

// The below listener gets invoked when the list is loaded 
... onPeopleLoaded(ConnectionResult cr, PersonBuffer pb, String nextPageToken) { 
    Person contact = null; 

    for (int i = 0; i < pb.getCount(); i++) { 
     contact = pb.get(i); 

     Log.d(TAG, contact.getDisplayName()); 
     Log.d(TAG, contact.getAboutMe() == null ? "Null" : contact.getAboutMe()); 
     Log.d(TAG, contact.getBirthday() == null ? "Null" : contact.getBirthday()); 
     Log.d(TAG, contact.getEmails() == null ? "Null" : contact.getEmails().toString()); 
     Log.d(TAG, contact.getCurrentLocation() == null ? "Null" : contact.getCurrentLocation()); 
     Log.d(TAG, contact.getId() == null ? "Null" : contact.getId()); 
     Log.d(TAG, contact.getLanguage() == null ? "Null" : contact.getLanguage()); 
     Log.d(TAG, contact.getUrl() == null ? "Null" : contact.getUrl()); 
     Log.d(TAG, contact.getName() == null ? "Null" : contact.getName().toString()); 
     Log.d(TAG, contact.isPlusUser() ? "true" : "false"); 
     Log.d(TAG, contact.isVerified() ? "true" : "false"); 
    } 
} 

在上面的代碼段中,未返回null唯一方法是: - getDisplayName - 的getId - 使用getURL

...和我所有的聯繫人(幾百)。這看起來像包含在我的方法onPeopleLoaded中收到的PersonBuffer中的Person對象是不完整的。對於我的許多聯繫人,我在他們的G +個人資料上看到的信息是可見的(他們正在與我分享)...

在旁註中,我嘗試了API瀏覽器(https://developers.google.com/+/api/latest/people/get),仍然收到部分數據,但至少,下面的2個方法似乎是工作,而他們不是我的Android應用程序: - isPlusUser - isVerified

任何信息解釋這種行爲將不勝感激。

回答

1

並非所有數據都可用於每個用戶。只有用戶在其個人資料中設置爲公開的數據或者訪問在授權對話框中明確授予的數據。根據您指定的PLUS_LOGIN範圍,您至少可以預期:基本配置文件數據(名稱,ID,照片,配置文件URL),ageRange,語言以及應用程序可見的朋友列表。除此之外的任何內容都必須由用戶在其Google+個人資料中明確公開。

如果您在使用getter之前需要檢查數據是否存在,還有「has」方法。有關所有配置文件方法,請參閱com.google.android.gms.plus.model.people.Person