Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android:httppost索引处的查询中存在非法字符_Java_Android_Facebook Graph Api - Fatal编程技术网

Java Android:httppost索引处的查询中存在非法字符

Java Android:httppost索引处的查询中存在非法字符,java,android,facebook-graph-api,Java,Android,Facebook Graph Api,我试图解析从graph facebook返回的json,这是一个页面的提要。 url如下所示: 但我得到了一个错误:索引7处的查询中存在非法字符。索引77处的字符是“|”。我的代码: private JSONObject getJSONFromUrl(String url) throws UnsupportedEncodingException { // Making HTTP request InputStream is = null; JSON

我试图解析从graph facebook返回的json,这是一个页面的提要。 url如下所示:

但我得到了一个错误:索引7处的查询中存在非法字符。索引77处的字符是“|”。我的代码:

private JSONObject getJSONFromUrl(String url) throws UnsupportedEncodingException {
        // Making HTTP request
        InputStream is = null;
        JSONObject jObj = null;
        String json = "";
        try {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();
        } 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();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }
        // try parse the string to a JSON object
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }
        // return JSON String
        return jObj;
    }
如果使用编码器替换URL,如下所示:

String url = "https://graph.facebook.com/pageId/feed?access_token=MyAppId" + URLEncoder.encode("|", "UTF-8") + "mySecretKey&limit=10";
我收到错误消息:

{“error”:{“message”:(#200)用户尚未授权应用程序执行此操作”,“type”:“OAutheException”,“code”:200}

但是如果我复制并粘贴原始URL,它将成功返回JSON


如何正确发送此案例中的url?

只是为了确保这不是一个简单的打字错误:使用编码器的代码上的
access\u token
有一个打字错误。应该是
access\u token
。您的问题标题没有描述问题。这似乎是一个身份验证问题。或者,或者尝试使用
HttpGet
,因为当您在浏览器上复制粘贴的URL时,实际上是通过HTTP GET完成的,而不是HTTP POST。(不确定,但试试也无妨)安德鲁,你说得对!Epic失败…HTTPGET解决了问题。