图形请求错误500

GPa*_*ack 8 android facebook-graph-api facebook-android-sdk

我的应用程序使用facebook-android-sdk的Facebook登录按钮.它一直工作到最后几天,现在是关于页面提要的图表请求

Bundle parameters = new Bundle();
parameters.putString("fields", "id,icon,created_time,name,caption,description,message,link,full_picture,shares");
parameters.putString("limit", "50");
parameters.putString("locale", mLocale);
String pathPosts = path + "/posts";
GraphRequest request = new GraphRequest(
        AccessToken.getCurrentAccessToken(), pathPosts, parameters, HttpMethod.GET,
        new GraphRequest.Callback() {
            @Override
            public void onCompleted(
                GraphResponse response) {
                mResponse = response;
                }
        });
request.executeAndWait();
Run Code Online (Sandbox Code Playgroud)

我收到了OAuthException错误

{Response:responseCode:500,graphObject:null,error:{HttpStatus:500,errorCode:1,errorType:OAuthException,errorMessage:发生了未知错误.}}

更新 发现,当限制低于33时,它可以正常工作

parameters.putString("limit", "33");
Run Code Online (Sandbox Code Playgroud)

对于另一个页面的Feed,限制必须低于7才能正常工作

parameters.putString("limit", "7");
Run Code Online (Sandbox Code Playgroud)

问题:现在页面Feed的图表api请求中的限制规则是什么?

Asu*_*nda 3

Facebook Graph API 也有调试模式。您需要在 REST API 中传递一个额外的参数debug=all 。如果有任何问题,它也会在响应 JSON 中为您提供问题的原因。

引用 Facebook 文档 -

启用调试模式后,图形 API 响应可能包含附加字段来解释请求的潜在问题。要启用调试模式,请使用调试查询字符串参数。例如:

获取 graph.facebook.com /v2.3/me/friends access_token=...& debug=all

在您的代码中,尝试更改此设置

String pathPosts = path + "/posts";
Run Code Online (Sandbox Code Playgroud)

对此

String pathPosts = path + "/posts&debug=all";
Run Code Online (Sandbox Code Playgroud)

或者

在你的 Bundle 中添加一个额外的参数“debug”“all”

并检查您收到的调试消息

有关处理错误和调试 Graph API 的更多信息,请参阅此处 - https://developers.facebook.com/docs/graph-api/using-graph-api/#errors