Android 使用HttpsUrlConnection获取帖子评论
我想使用HttpsUrlConnection获取Facebook帖子的评论 这是url{my_access_token}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
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。