Java FacebookGraphAPI:querying/me/photos工作正常,但是/me/photos?limit=100返回一个错误
我试过查询状态,喜欢,照片,一切都很好 但是,当我在字符串末尾添加一个limit“?limit=100”时,我从响应对象中得到一个错误,错误类型为:OAutheException,错误消息:必须使用活动访问令牌来查询有关当前用户的信息 我的代码的相关部分如下:Java FacebookGraphAPI:querying/me/photos工作正常,但是/me/photos?limit=100返回一个错误,java,android,facebook,facebook-graph-api,Java,Android,Facebook,Facebook Graph Api,我试过查询状态,喜欢,照片,一切都很好 但是,当我在字符串末尾添加一个limit“?limit=100”时,我从响应对象中得到一个错误,错误类型为:OAutheException,错误消息:必须使用活动访问令牌来查询有关当前用户的信息 我的代码的相关部分如下: Request rq3 = new Request(Session.getActiveSession(), "/me/statuses?limit=100", null, HttpMethod.GET, new Request.Callb
Request rq3 = new Request(Session.getActiveSession(), "/me/statuses?limit=100", null, HttpMethod.GET, new Request.Callback() {
@Override
public void onCompleted(Response response) {
parseFeed(response, 2);
getNext(response, 2);
}
});
rq3.executeAsync();
private void parseFeed(Response response, int type) {
try {
Log.v("response", response.toString());
JSONArray feedArr = response.getGraphObject().getInnerJSONObject().getJSONArray("data");
switch(type) {
case 0:
numLikes += feedArr.length();
likesView.setText("Likes: " + String.valueOf(numLikes));
break;
case 1:
numPhotos += feedArr.length();
photosView.setText("Photos: " + String.valueOf(numPhotos));
break;
case 2:
Log.v("response", response.toString());
numStatuses += feedArr.length();
statusesView.setText("Statuses: " + String.valueOf(numStatuses));
break;
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void getNext(Response response, final int type) {
Request next = response.getRequestForPagedResults(Response.PagingDirection.NEXT);
if (next != null) {
Log.v("status", "getting next");
next.setCallback(new Request.Callback() {
@Override
public void onCompleted(Response response) {
// TODO Auto-generated method stub
parseFeed(response, type);
getNext(response, type);
}
});
Request.executeBatchAsync(next);
}
else {
Log.v("status", "ended");
}
}
参数与Graph API请求一起传递的附加参数;参数必须是字符串、数字、位图、日期或字节数组
根据,参数不应是图形路径的一部分。实际上,您正在传递一个null
包
正确用法:
Bundle params = new Bundle();
params.putString("limit", 100);
Request rq3 = new Request(Session.getActiveSession(),
"/me/statuses",
params,
HttpMethod.GET,
new Request.Callback() {
@Override
public void onCompleted(Response response) {
parseFeed(response, 2);
getNext(response, 2);
}
}
);
请求(会话、字符串、捆绑包、HttpMethod)不是请求(会话、字符串)。。。。我很确定这个api在/me/statuses?limit=100
的末尾添加了?some_ouath_param=some_oauth_value
,现在url是f了…也许使用带有键限制和值100的Bundle就可以了。。。ps我从未使用过graph api:P,但我对google.com和阅读文档很在行……是的,我已经将参数添加到了一个包中,解决了这个问题。非常感谢。
Bundle params = new Bundle();
params.putString("limit", 100);
Request rq3 = new Request(Session.getActiveSession(),
"/me/statuses",
params,
HttpMethod.GET,
new Request.Callback() {
@Override
public void onCompleted(Response response) {
parseFeed(response, 2);
getNext(response, 2);
}
}
);