Android 中的 Facebook 请求问题

发布于 2024-10-21 13:11:33 字数 3908 浏览 3 评论 0原文

我正在使用 facebook-android-sdk 将消息发布到我的墙上。

以下请求:

Bundle params = new Bundle();

params.putString("message", "test message");

mAsyncRunner = new AsyncFacebookRunner(mFacebook);
mAsyncRunner.request("me/feed", params, "POST", new PostRequestListener(), null);  

返回如下所示的警告,尽管该消息正确显示在墙上。

将消息转换为字节时,如 Stackoverflow 上的类似问题所示:

params.putByteArray("message", "test message".Bytes());

不再有 Key 消息的警告,帖子显示在 Facebook 墙上,但没有消息。

怎么了?

谢谢。

警告:

03-14 11:35:01.635: WARN/Bundle(9963): Key message expected byte[] but value was a java.lang.String.  The default value <null> was returned.
03-14 11:35:01.675: WARN/Bundle(9963): Attempt to cast generated internal exception:
03-14 11:35:01.675: WARN/Bundle(9963): java.lang.ClassCastException: java.lang.String
03-14 11:35:01.675: WARN/Bundle(9963):     at android.os.Bundle.getByteArray(Bundle.java:1305)
03-14 11:35:01.675: WARN/Bundle(9963):     at com.facebook.android.Util.encodePostBody(Util.java:63)
03-14 11:35:01.675: WARN/Bundle(9963):     at com.facebook.android.Util.openUrl(Util.java:182)
03-14 11:35:01.675: WARN/Bundle(9963):     at com.facebook.android.Facebook.request(Facebook.java:559)
03-14 11:35:01.675: WARN/Bundle(9963):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)
03-14 11:35:01.685: WARN/Bundle(9963): Key method expected byte[] but value was a java.lang.String.  The default value <null> was returned.
03-14 11:35:01.725: WARN/Bundle(9963): Attempt to cast generated internal exception:
03-14 11:35:01.725: WARN/Bundle(9963): java.lang.ClassCastException: java.lang.String
03-14 11:35:01.725: WARN/Bundle(9963):     at android.os.Bundle.getByteArray(Bundle.java:1305)
03-14 11:35:01.725: WARN/Bundle(9963):     at com.facebook.android.Util.encodePostBody(Util.java:63)
03-14 11:35:01.725: WARN/Bundle(9963):     at com.facebook.android.Util.openUrl(Util.java:182)
03-14 11:35:01.725: WARN/Bundle(9963):     at com.facebook.android.Facebook.request(Facebook.java:559)
03-14 11:35:01.725: WARN/Bundle(9963):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)
03-14 11:35:01.735: WARN/Bundle(9963): Key access_token expected byte[] but value was a java.lang.String.  The default value <null> was returned.
03-14 11:35:01.775: WARN/Bundle(9963): Attempt to cast generated internal exception:
03-14 11:35:01.775: WARN/Bundle(9963): java.lang.ClassCastException: java.lang.String
03-14 11:35:01.775: WARN/Bundle(9963):     at android.os.Bundle.getByteArray(Bundle.java:1305)
03-14 11:35:01.775: WARN/Bundle(9963):     at com.facebook.android.Util.encodePostBody(Util.java:63)
03-14 11:35:01.775: WARN/Bundle(9963):     at com.facebook.android.Util.openUrl(Util.java:182)
03-14 11:35:01.775: WARN/Bundle(9963):     at com.facebook.android.Facebook.request(Facebook.java:559)
03-14 11:35:01.775: WARN/Bundle(9963):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)
03-14 11:35:01.785: WARN/Bundle(9963): Key format expected byte[] but value was a java.lang.String.  The default value <null> was returned.
03-14 11:35:01.825: WARN/Bundle(9963): Attempt to cast generated internal exception:
03-14 11:35:01.825: WARN/Bundle(9963): java.lang.ClassCastException: java.lang.String
03-14 11:35:01.825: WARN/Bundle(9963):     at android.os.Bundle.getByteArray(Bundle.java:1305)
03-14 11:35:01.825: WARN/Bundle(9963):     at com.facebook.android.Util.encodePostBody(Util.java:63)
03-14 11:35:01.825: WARN/Bundle(9963):     at com.facebook.android.Util.openUrl(Util.java:182)
03-14 11:35:01.825: WARN/Bundle(9963):     at com.facebook.android.Facebook.request(Facebook.java:559)
03-14 11:35:01.825: WARN/Bundle(9963):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)

I'm using facebook-android-sdk to post messages to my wall.

The following request:

Bundle params = new Bundle();

params.putString("message", "test message");

mAsyncRunner = new AsyncFacebookRunner(mFacebook);
mAsyncRunner.request("me/feed", params, "POST", new PostRequestListener(), null);  

returns the warnings shown below, although the message is shown correctly on the wall.

When converting the message to bytes, as seen in similar questions on Stackoverflow:

params.putByteArray("message", "test message".Bytes());

there is no more warnings for Key message, and the post is shown on the Facebook wall, but with no message.

What's wrong?

Thanks.

Warnings:

03-14 11:35:01.635: WARN/Bundle(9963): Key message expected byte[] but value was a java.lang.String.  The default value <null> was returned.
03-14 11:35:01.675: WARN/Bundle(9963): Attempt to cast generated internal exception:
03-14 11:35:01.675: WARN/Bundle(9963): java.lang.ClassCastException: java.lang.String
03-14 11:35:01.675: WARN/Bundle(9963):     at android.os.Bundle.getByteArray(Bundle.java:1305)
03-14 11:35:01.675: WARN/Bundle(9963):     at com.facebook.android.Util.encodePostBody(Util.java:63)
03-14 11:35:01.675: WARN/Bundle(9963):     at com.facebook.android.Util.openUrl(Util.java:182)
03-14 11:35:01.675: WARN/Bundle(9963):     at com.facebook.android.Facebook.request(Facebook.java:559)
03-14 11:35:01.675: WARN/Bundle(9963):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)
03-14 11:35:01.685: WARN/Bundle(9963): Key method expected byte[] but value was a java.lang.String.  The default value <null> was returned.
03-14 11:35:01.725: WARN/Bundle(9963): Attempt to cast generated internal exception:
03-14 11:35:01.725: WARN/Bundle(9963): java.lang.ClassCastException: java.lang.String
03-14 11:35:01.725: WARN/Bundle(9963):     at android.os.Bundle.getByteArray(Bundle.java:1305)
03-14 11:35:01.725: WARN/Bundle(9963):     at com.facebook.android.Util.encodePostBody(Util.java:63)
03-14 11:35:01.725: WARN/Bundle(9963):     at com.facebook.android.Util.openUrl(Util.java:182)
03-14 11:35:01.725: WARN/Bundle(9963):     at com.facebook.android.Facebook.request(Facebook.java:559)
03-14 11:35:01.725: WARN/Bundle(9963):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)
03-14 11:35:01.735: WARN/Bundle(9963): Key access_token expected byte[] but value was a java.lang.String.  The default value <null> was returned.
03-14 11:35:01.775: WARN/Bundle(9963): Attempt to cast generated internal exception:
03-14 11:35:01.775: WARN/Bundle(9963): java.lang.ClassCastException: java.lang.String
03-14 11:35:01.775: WARN/Bundle(9963):     at android.os.Bundle.getByteArray(Bundle.java:1305)
03-14 11:35:01.775: WARN/Bundle(9963):     at com.facebook.android.Util.encodePostBody(Util.java:63)
03-14 11:35:01.775: WARN/Bundle(9963):     at com.facebook.android.Util.openUrl(Util.java:182)
03-14 11:35:01.775: WARN/Bundle(9963):     at com.facebook.android.Facebook.request(Facebook.java:559)
03-14 11:35:01.775: WARN/Bundle(9963):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)
03-14 11:35:01.785: WARN/Bundle(9963): Key format expected byte[] but value was a java.lang.String.  The default value <null> was returned.
03-14 11:35:01.825: WARN/Bundle(9963): Attempt to cast generated internal exception:
03-14 11:35:01.825: WARN/Bundle(9963): java.lang.ClassCastException: java.lang.String
03-14 11:35:01.825: WARN/Bundle(9963):     at android.os.Bundle.getByteArray(Bundle.java:1305)
03-14 11:35:01.825: WARN/Bundle(9963):     at com.facebook.android.Util.encodePostBody(Util.java:63)
03-14 11:35:01.825: WARN/Bundle(9963):     at com.facebook.android.Util.openUrl(Util.java:182)
03-14 11:35:01.825: WARN/Bundle(9963):     at com.facebook.android.Facebook.request(Facebook.java:559)
03-14 11:35:01.825: WARN/Bundle(9963):     at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

家住魔仙堡 2024-10-28 13:11:33

这是 facebook SDK 中的一个错误,请参阅此答案进行修复。

It's a bug in facebook's SDK, see this answer for a fix.

我还不会笑 2024-10-28 13:11:33

同样的问题请查看 Facebook 帖子

好的,尝试用这种方式张贴在墙上

Bundle parameters = new Bundle();
parameters.putString("method", "stream.publish");
parameters.putString("attachment",
"{\"name\":\""
+ b.getString("title")
+ "\",\"description\":\""
+ desc
+ "\"}]}");
    authenticatedFacebook.dialog(DealCities_View.this, "stream.publish",
                                    parameters, new TestUiServerListener());

Same question check it out Facebook Post

Okay try this way to post on wall

Bundle parameters = new Bundle();
parameters.putString("method", "stream.publish");
parameters.putString("attachment",
"{\"name\":\""
+ b.getString("title")
+ "\",\"description\":\""
+ desc
+ "\"}]}");
    authenticatedFacebook.dialog(DealCities_View.this, "stream.publish",
                                    parameters, new TestUiServerListener());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文