[英]Facebook api android get friend list
我在Android應用和Facebook個人資料之間實現了身份驗證。 我能夠獲取登錄的用戶數據。 但是,我要求讓用戶(僅)玩游戲(步驟1)。
到目前為止,這是我的代碼:
GraphRequest request = new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{user-id}/friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
}
}
).executeAsync();
從技術上講,我的回復應為JSON格式,並且我應該能夠從中獲取所需信息。 但是,每當我嘗試我的項目凍結並重新啟動時。
對於步驟2,您對如何從我的應用程序發送最高分數並將其發布到Facebook上,然后在我得到玩游戲的好友列表后能夠檢索並顯示它有任何建議嗎?
謝謝
我能夠使用線程解決它。
final GraphRequest request_getFriends = new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + AccessToken.getCurrentAccessToken().getUserId() + "/friends?",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
JSONObject object = response.getJSONObject();
try {
if (object !=null){
JSONArray data = object.getJSONArray("data");
for (int i = 0; i < data.length(); i++) {
String id = data.getJSONObject(i).getString("id");
String name = data.getJSONObject(i).getString("name");
ListOfFriendsIDS.add(id);
ListOfFriendsNames.add(name);
}
}
} catch (JSONException e) {
}
}
}
);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
request_getFriends.executeAndWait();
}
}
);
t.start();
之前的代碼是異步執行的,因此我的結果無法正確獲取。
使用此GameRequestDialog加載非應用程序用戶的朋友。
GameRequestDialog dialog;
GameRequestContent content = new
GameRequestContent.Builder().
setTitle("title").
setMessage("message").
setFilters(GameRequestContent.Filters.APP_NON_USERS)
.build();
dialog.show(content);
伴隨着此,通過它將會提供很大的幫助。 這是facebook實現的示例項目。
https://github.com/fbsamples/android-friend-smash
希望能有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.