Error code 2500 Facebook graph api

joselufo picture joselufo · Nov 28, 2013 · Viewed 10.8k times · Source

I do not understand why this query does not work in android and "Graph Api Explorer" if it

111891332274505?fields=albums.fields(id,name,description,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 "?"." at character 6: photos?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.

In the end what I have done is to build the url and request data through the 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;
 }

Answer

Rahil Arora picture Rahil Arora · Nov 28, 2013

There should be an ampersand sign & just before the access_token parameter. 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.