[英]graph api for facebook friend
這是我的代碼,我已使用它從Facebook檢索用戶朋友列表,但此錯誤代碼返回空:
{Response:responseCode:200,graphObject:GraphObject {graphObjectClass = GraphObject,state = {“ data”:[]}},error:null,isFromCache:false}
{
“數據”:[]
}
我的代碼:
String fqlQuery = "SELECT uid, name, pic_square FROM user WHERE uid IN " +
"(SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 25)";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Session session = Session.getActiveSession();
Request request = new Request(session,"/fql", params,HttpMethod.GET, new Request.Callback(){
public void onCompleted(Response response) {
Log.i(TAG, "Result: " + response.toString());
try{
GraphObject graphObject = response.getGraphObject();
JSONObject jsonObject = graphObject.getInnerJSONObject();
Log.d("data", jsonObject.toString(0));
JSONArray array = jsonObject.getJSONArray("data");
for(int i=0;i<array.length();i++)
{
JSONObject friend = array.getJSONObject(i);
Log.d("uid",friend.getString("uid"));
Log.d("name", friend.getString("name"));
Log.d("pic_square",friend.getString("pic_square"));
}
}catch(JSONException e){
e.printStackTrace();
}
}
});
Request.executeBatchAsync(request);
給我解決方案。
如果您的應用是2014年4月30日之后創建的,那么您將無法獲取所有朋友的列表。
使用GraphAPI,您只能獲取正在使用您的應用程序的朋友的列表,您可以查看有關API 2.0版的常見問題解答。
另外,您可能想查看有關您的問題的“錯誤”報告,該報告已通過設計確認。
編輯:
Bundle params = new Bundle();
params.putString("fields", "uid, name, pic_square");
Request request = new Request(session, "me/friends", params, HttpMethod.GET, new Request.Callback() {
@Override
public void onCompleted(Response response) {
if (response.getGraphObject() != null) {
Log.i("GA_REQ_RESPONSE", "Got results: " + response.toString());
//handle response
} catch (JSONException ex) {
Log.i(JSON_TAG, "JSON Exception: " + ex.getMessage());
}
} else {
}
}
});
request.executeAsync();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.