java.net.UnknownHostException:graph.facebook.com
尝试将照片发布到用户墙时,我收到 UnknownHostException。 这是我的代码:
byte[] data = null;
Bitmap bi = BitmapFactory.decodeResource(getResources(), aDrawableId);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 70, baos);
data = baos.toByteArray();
Bundle parameters = new Bundle();
parameters.putByteArray("picture", data);
Log.i(getClass().toString(), parameters.toString());
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(this.facebook);
String method = String.format("me/photos?access_token=%s", this.facebook.getAccessToken());
mAsyncRunner.request(method, parameters, "POST", new FacebookRequestListener(), null);
我的 AndroidManifest 文件的权限:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
我之前遇到了与以下问题相同的问题,我使用第二个答案(投票最高的一个)进行更正:
从 android fb sdk 向 facebook 墙发布消息总是错误
我收到的唯一消息logcat 是:
10-26 15:29:16.425: E/Facebook(5342): java.net.UnknownHostException: graph.facebook.com
你们对如何解决这个问题有什么想法吗?我正在普通 Galaxy S2 设备上运行该应用程序。
I'm getting a UnknownHostException when trying to post a photo to the user wall.
Here is my code:
byte[] data = null;
Bitmap bi = BitmapFactory.decodeResource(getResources(), aDrawableId);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 70, baos);
data = baos.toByteArray();
Bundle parameters = new Bundle();
parameters.putByteArray("picture", data);
Log.i(getClass().toString(), parameters.toString());
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(this.facebook);
String method = String.format("me/photos?access_token=%s", this.facebook.getAccessToken());
mAsyncRunner.request(method, parameters, "POST", new FacebookRequestListener(), null);
The permissions on my AndroidManifest file:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I had the same problem as the following question before and I correct using the second answer (the top voted one):
Post message to facebook wall from android fb sdk always error
The only message I get in logcat is:
10-26 15:29:16.425: E/Facebook(5342): java.net.UnknownHostException: graph.facebook.com
Do you guys have any ideas on how to solve this? I'm running the app on a stock Galaxy S2 device.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是否会解决您遇到的错误,但我注意到了一些事情:
文档(在照片连接下)指出图片参数名为源(而不是您使用的图片) 。
facebook sdk 将访问令牌添加到 api 请求中,因此您不需要这样做(您可以查看 source。我不认为这对于 POST 请求来说应该是一个问题,但是如果你使用 GET 那么sdk添加“?”到路径,在你的情况下,你最终会找到其中的两个
问题吗?
I'm not sure if this will fix the error you get, but a few things I noticed:
The documentation (under the Photos connection) states the the picture parameter is named source (and not picture as you used).
The facebook sdk adds the access token to the api requests, so you don't need to do that (you can look at the source. I don't think that it should be a problem for POST requests, but if you use GET then the sdk adds "?" to the path, and in your case you'll end up with two of those.
Have you managed to find the problem?