【问题标题】:Error code 2500 Facebook graph api错误代码 2500 Facebook 图形 API
【发布时间】:2013-11-28 17:49:32
【问题描述】:

我不明白为什么这个查询在 android 和“Graph Api Explorer”中不起作用

111891332274505?fields=albums.fields(id,name,description,updated_time,created_time,cover_photo)

错误代码

错误代码:2500 错误信息:{HttpStatus: 400, errorCode: 2500, errorType:OAuthException,errorMessage:语法错误“预期结束 字符串而不是字符 6 处的 "?".": 照片?access_token=XXXXXXXXXXXX}

代码

     public void getAlbumFacebook () {
     Request request = new Request(session, "/111891332274505?fields=albums.fields(id,name,description,updated_time,created_time,cover_photo)", null, HttpMethod.GET, new Request.Callback() {
        @Override
        public void onCompleted(Response response) {
            GraphObject graphObject = response.getGraphObject();
            FacebookRequestError error = response.getError();

             if (error != null) {
                 DebugLog.log("Error code: " + error.getErrorCode() + " Error mensaje: " + error.toString());

            }

            if (graphObject != null) {
                JSONArray jsonArray = (JSONArray) graphObject.getProperty("data");
                DebugLog.log("JSON Facebook "+ jsonArray.toString());
            } else {
                 DebugLog.log("Es null");

            }
        }
    });

    Request.executeBatchAsync(request);
 }

解决方案

我已经能够解决我可以推断的问题是“请求”类无法咨询插入的字段。

最后我所做的是构建url并通过url请求数据。

构建网址

 String id = "111891332274505";
 String url = "https://graph.facebook.com/" + id + "/albums?access_token=" + session.getAccessToken() + "&fields=id,name,description,updated_time";

代码请求

     public JSONObject getRequestFromUrl (String url) {
     try {
         httpClient = new DefaultHttpClient();
         HttpGet get = new HttpGet(url);

         HttpResponse httpResponse = httpClient.execute(get);
         HttpEntity responseEntity = httpResponse.getEntity();
         is = responseEntity.getContent();
         DebugLog.log("Estoy aqui");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;

        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");             
        }

        is.close();
        json = sb.toString();
        Log.e("JSON", json);
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }

    return jObj;
 }

【问题讨论】:

  • 您需要包含您的用户访问令牌。
  • 谢谢@hichris123,但是如何包含用户的访问令牌?
  • 你通过OAuth认证了吗?
  • 是的,如果我将查询更改为此“/111891332274505/albums”有效,但当我输入字段并给我该错误时,我已登录到 facebook 并且会话对象也已打开。跨度>
  • 哦,看看这个。 Syntax error "Expected end of string instead of "?"." at character 6: photos?access_token=XXXXXXXXXXXX}我看一下API参考。

标签: android facebook facebook-graph-api facebook-android-sdk facebook-sdk-3.0


【解决方案1】:

access_token 参数之前应该有一个 & 符号 &。但是现在,一个 ? 被附加在该参数之前。问题是在 URL 中附加 ? 而不是 & 的代码部分。

【讨论】:

    【解决方案2】:

    RestFB for java 你可以使用Parameter 类。

    Parameter.with("fields", "albums.fields(id,name,description,updated_time,created_time,cover_photo") 在您的示例中。 (API 可能会改变)

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题,但使用的是 GraphRequest 类,所以我会为它写。

      GraphRequest 会生成这样的 URL

      ...facebook.com/111891332274505?fields=albums...?access_token=...
      

      而不是

      ...facebook.com/111891332274505?fields=albums...&access_token=...
      

      应该如此。

      解决方案:

      GraphRequest request =  GraphRequest.newGraphPathRequest(access_token, "111891332274505",...);
      
      Bundle parameters = new Bundle();
      
      parameters.putString("fields", "albums...");
      
      request.setParameters(parameters);
      
      request.executeAsync();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-27
        • 2012-12-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多