这是我用来从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);
请给我解决方案。
答案 0 :(得分:0)
如果您的应用是在2014年4月30日之后创建的,那么您无法获得所有朋友的列表。
使用GraphAPI,您只能获取正在使用您的应用的朋友列表,您可以查看有关2.0版API的常见问题解答。
FAQ: API v2.0 and the New Facebook Login
另外,您可能需要检查“错误”。报告您的问题,并通过设计确认。
No way to get all friends of "me" with a permanent ID
编辑:
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();