2

我不明白为什么这个查询没有在Android的工作, “图形API资源管理器”,如果它错误代码2500的Facebook图形API

111891332274505?场= albums.fields(ID,名称,描述,updated_time ,CREATED_TIME,cover_photo)

错误代码

错误代码:2500错误mensaje:{的HTTPStatus:400,错误码: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); 
} 

SOLUTION

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

最后我所做的是通过url构建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; 
} 
+0

您需要包括用户的访问令牌。 – hichris123

+0

谢谢@ hichris123,但如何为用户包含访问令牌? – TeRRo

+0

您是否已经通过OAuth身份验证? – hichris123

回答

7

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

0

通过RestFB对于java,您可以使用Parameter类。

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

-1

我有同样的问题,但与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(); 
+0

虽然此链接可以回答这个问题,最好是包括这里的答案的主要部分,并提供链接供参考,链接的答案可能会失效,如果链接的页面更改 –

+0

嗯,我想这是它投票的原因。 – Darko