Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.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
Android 使用HttpsUrlConnection获取帖子评论_Android_Facebook_Facebook Graph Api - Fatal编程技术网

Android 使用HttpsUrlConnection获取帖子评论

Android 使用HttpsUrlConnection获取帖子评论,android,facebook,facebook-graph-api,Android,Facebook,Facebook Graph Api,我想使用HttpsUrlConnection获取Facebook帖子的评论 这是url{my_access_token} String urlAddress = "https://graph.facebook.com/" + postId + "/comments?access_token=" + "{my_access_token}"; try { URL url = new URL(urlAddress); HttpsURLCo

我想使用HttpsUrlConnection获取Facebook帖子的评论 这是url{my_access_token}

String urlAddress = "https://graph.facebook.com/" + postId + "/comments?access_token=" + "{my_access_token}";
        try {
            URL url = new URL(urlAddress);
            HttpsURLConnection httpURLConnection = (HttpsURLConnection) url
                    .openConnection();
            httpURLConnection.setDoInput(true);
            httpURLConnection.setDoOutput(true);
            httpURLConnection.setReadTimeout(10000);
            httpURLConnection.setConnectTimeout(10000);
            httpURLConnection.setRequestMethod("GET");
            String response = ConnectionController.getResponse(httpURLConnection);
            Log.v(Constants.TAG, urlAddress);
            Log.v(Constants.TAG, response);

        } catch (IOException e) {
            e.printStackTrace();
        }
它在浏览器上运行得很好,但在Android中我得到了FileNotFoundException


注意:我不想使用Facebook SDK或任何其他库从代码中删除
setDoOutput(true)
调用。这仅在您执行POST请求时才需要,如果将它放在此处作为GET请求,将导致出现
FileNotFoundException

未找到哪个文件?这似乎是您的构建的问题,而不是APInot构建的问题,请看这篇文章,您是否验证了
postId
是否具有正确的值?实际上,你的访问令牌周围没有花括号,对吗?如果您将完整的URL作为静态值写入代码,而不将变量放入其中,是否会得到相同的结果?是的,我在浏览器中尝试了相同的URL,它可以工作。您应该调用
httpURLConnection.getResponseCode()
,以查看服务器返回的错误。另外,请确保您正在调用的服务器可以处理Https,而不仅仅是Http。