简体   繁体   English

错误代码2500 Facebook图形API

[英]Error code 2500 Facebook graph api

I do not understand why this query does not work in android and "Graph Api Explorer" if it 我不明白为什么这个查询在android和“ Graph Api Explorer”中不起作用

111891332274505?fields=albums.fields(id,name,description,updated_time,created_time,cover_photo) 111891332274505?字段= albums.fields(ID,名称,描述,updated_time,CREATED_TIME,cover_photo)

Error Code 错误代码

Error code: 2500 Error mensaje: {HttpStatus: 400, errorCode: 2500, errorType: OAuthException, errorMessage: Syntax error "Expected end of string instead of "?"." 错误代码:2500错误菜单:{HttpStatus:400,错误代码:2500,错误类型:OAuthException,错误消息:语法错误“字符串的预期结尾而不是“?”。” at character 6: photos?access_token=XXXXXXXXXXXX} 在第6个字符处:照片?access_token = XXXXXXXXXXXX}

Code

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

SOLUTION

I've already been able to solve the problem I can deduce is that the "Request" class can not consult with inserted fields. 我已经能够解决我可以推断出的问题,即“ Request”类无法与插入的字段进行协商。

In the end what I have done is to build the url and request data through the url. 最后,我要做的是构建URL并通过URL请求数据。

Build URL 建立网址

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

Code request 代码要求

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

There should be an ampersand sign & just before the access_token parameter. 应该有一个&符号刚刚之前access_token参数。 But right now, a ? 但是现在,一个 is being appended before that parameter. 被附加到该参数之前。 The problem is the part of the code that is appending the ? 问题是附加了的代码部分 instead of & in the URL. 而不是网址中的

By RestFB for java you can make use of Parameter class. 通过RestFB for Java,您可以使用Parameter类。

Parameter.with("fields", "albums.fields(id,name,description,updated_time,created_time,cover_photo") in your example. (API may change) Parameter.with("fields", "albums.fields(id,name,description,updated_time,created_time,cover_photo") 。(API可能会更改)

I had the same problem but with GraphRequest class, so I'll write for it. 我遇到了同样的问题,但是使用了GraphRequest类,所以我将为其编写。

GraphRequest will make URL like this GraphRequest将使URL像这样

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

instead of 代替

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

as it should be. 应该是。

Solution: 解:

GraphRequest request =  GraphRequest.newGraphPathRequest(access_token, "111891332274505",...);

Bundle parameters = new Bundle();

parameters.putString("fields", "albums...");

request.setParameters(parameters);

request.executeAsync();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM