Facebook Graph API:查询/我/照片工作正常,但是/ me / photos?limit = 100会返回错误

时间:2014-06-17 14:32:48

标签: java android facebook facebook-graph-api

我尝试过查询状态,喜欢,照片,一切正常。

但是当我添加一个限制"?limit = 100"到字符串的末尾,我从带有errorType的Response对象中收到错误:OAuthException,errorMessage:必须使用活动访问令牌来查询有关当前用户的信息

我的代码的相关部分如下:

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");
    }
}

1 个答案:

答案 0 :(得分:1)

Request(Session, String, Bundle, HttpMethod, Callback)
  

参数与图谱API请求一起传递的其他参数;参数必须是字符串,数字,位图,日期或字节数组。

根据doc,参数不应该是图形路径的一部分。您实际上正在传递null Bundle


正确的用法:

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);
                              }
                          }
                     );