Android Facebook 贴在墙上没有对话框警告

标签 android facebook facebook-graph-api ddms

我按照这个方法在没有对话框的情况下发布 Facebook 状态更新,来自 SO 上的这个答案:https://stackoverflow.com/a/7528388/450534

我可以发布应用 Activity 的状态更新,但它仍在生成警告。

这是来自 DDMS 的一长串警告。任何有关解决问题的建议都将受到赞赏。

代码:

protected void postToWall(String message) {

        if (!Utility.mFacebook.isSessionValid()) {
            Util.showAlert(this, "Warning", "You must first log in.");
        }

        Log.d("Tests", "Testing graph API wall post");
        try {
            String response = Utility.mFacebook.request("me");
            Bundle parameters = new Bundle();
            parameters.putString("message", txtPostToWall.getText().toString());
//          parameters.putString("description", getString(R.string.app_desc));

            response = Utility.mFacebook.request("me/feed", parameters, "POST");
            txtPostToWall.setText("");
            this.finish();

            Log.d("Tests", "got response: " + response);

            if (response == null || response.equals("") ||  response.equals("false"))   {
                Log.v("Error", "Blank response");
            }
        }
        catch(Exception e)  {
            e.printStackTrace();
        }
    }

DDMS 警告:(非常非常冗长。)

03-30 20:02:53.290: W/Bundle(17941): Key message expected byte[] but value was a java.lang.String.  The default value <null> was returned.
    03-30 20:02:53.306: W/Bundle(17941): Attempt to cast generated internal exception:
    03-30 20:02:53.306: W/Bundle(17941): java.lang.ClassCastException: java.lang.String
    03-30 20:02:53.306: W/Bundle(17941):    at android.os.Bundle.getByteArray(Bundle.java:1305)
    03-30 20:02:53.306: W/Bundle(17941):    at com.facebook.android.Util.openUrl(Util.java:161)
    03-30 20:02:53.306: W/Bundle(17941):    at com.facebook.android.Facebook.request(Facebook.java:751)
    03-30 20:02:53.306: W/Bundle(17941):    at com.dzinesunlimited.sociallyyou.StatusUpdate.postToWall(StatusUpdate.java:68)
    03-30 20:02:53.306: W/Bundle(17941):    at com.dzinesunlimited.sociallyyou.StatusUpdate$2.onClick(StatusUpdate.java:48)
    03-30 20:02:53.306: W/Bundle(17941):    at android.view.View.performClick(View.java:2538)
    03-30 20:02:53.306: W/Bundle(17941):    at android.view.View$PerformClick.run(View.java:9152)
    03-30 20:02:53.306: W/Bundle(17941):    at android.os.Handler.handleCallback(Handler.java:587)
    03-30 20:02:53.306: W/Bundle(17941):    at android.os.Handler.dispatchMessage(Handler.java:92)
    03-30 20:02:53.306: W/Bundle(17941):    at android.os.Looper.loop(Looper.java:130)
    03-30 20:02:53.306: W/Bundle(17941):    at android.app.ActivityThread.main(ActivityThread.java:3687)
    03-30 20:02:53.306: W/Bundle(17941):    at java.lang.reflect.Method.invokeNative(Native Method)
    03-30 20:02:53.306: W/Bundle(17941):    at java.lang.reflect.Method.invoke(Method.java:507)
    03-30 20:02:53.306: W/Bundle(17941):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
    03-30 20:02:53.306: W/Bundle(17941):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    03-30 20:02:53.306: W/Bundle(17941):    at dalvik.system.NativeStart.main(Native Method)
    03-30 20:02:53.310: W/Bundle(17941): Key access_token expected byte[] but value was a java.lang.String.  The default value <null> was returned.
    03-30 20:02:53.325: W/Bundle(17941): Attempt to cast generated internal exception:
    03-30 20:02:53.325: W/Bundle(17941): java.lang.ClassCastException: java.lang.String
    03-30 20:02:53.325: W/Bundle(17941):    at android.os.Bundle.getByteArray(Bundle.java:1305)
    03-30 20:02:53.325: W/Bundle(17941):    at com.facebook.android.Util.openUrl(Util.java:161)
    03-30 20:02:53.325: W/Bundle(17941):    at com.facebook.android.Facebook.request(Facebook.java:751)
    03-30 20:02:53.325: W/Bundle(17941):    at com.dzinesunlimited.sociallyyou.StatusUpdate.postToWall(StatusUpdate.java:68)
    03-30 20:02:53.325: W/Bundle(17941):    at com.dzinesunlimited.sociallyyou.StatusUpdate$2.onClick(StatusUpdate.java:48)
    03-30 20:02:53.325: W/Bundle(17941):    at android.view.View.performClick(View.java:2538)
    03-30 20:02:53.325: W/Bundle(17941):    at android.view.View$PerformClick.run(View.java:9152)
    03-30 20:02:53.325: W/Bundle(17941):    at android.os.Handler.handleCallback(Handler.java:587)
    03-30 20:02:53.325: W/Bundle(17941):    at android.os.Handler.dispatchMessage(Handler.java:92)
    03-30 20:02:53.325: W/Bundle(17941):    at android.os.Looper.loop(Looper.java:130)
    03-30 20:02:53.325: W/Bundle(17941):    at android.app.ActivityThread.main(ActivityThread.java:3687)
    03-30 20:02:53.325: W/Bundle(17941):    at java.lang.reflect.Method.invokeNative(Native Method)
    03-30 20:02:53.325: W/Bundle(17941):    at java.lang.reflect.Method.invoke(Method.java:507)
    03-30 20:02:53.325: W/Bundle(17941):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
    03-30 20:02:53.325: W/Bundle(17941):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    03-30 20:02:53.325: W/Bundle(17941):    at dalvik.system.NativeStart.main(Native Method)
    03-30 20:02:53.325: W/Bundle(17941): Key format expected byte[] but value was a java.lang.String.  The default value <null> was returned.
    03-30 20:02:53.341: W/Bundle(17941): Attempt to cast generated internal exception:
    03-30 20:02:53.341: W/Bundle(17941): java.lang.ClassCastException: java.lang.String
    03-30 20:02:53.341: W/Bundle(17941):    at android.os.Bundle.getByteArray(Bundle.java:1305)
    03-30 20:02:53.341: W/Bundle(17941):    at com.facebook.android.Util.openUrl(Util.java:161)
    03-30 20:02:53.341: W/Bundle(17941):    at com.facebook.android.Facebook.request(Facebook.java:751)
    03-30 20:02:53.341: W/Bundle(17941):    at com.dzinesunlimited.sociallyyou.StatusUpdate.postToWall(StatusUpdate.java:68)
    03-30 20:02:53.341: W/Bundle(17941):    at com.dzinesunlimited.sociallyyou.StatusUpdate$2.onClick(StatusUpdate.java:48)
    03-30 20:02:53.341: W/Bundle(17941):    at android.view.View.performClick(View.java:2538)
    03-30 20:02:53.341: W/Bundle(17941):    at android.view.View$PerformClick.run(View.java:9152)
    03-30 20:02:53.341: W/Bundle(17941):    at android.os.Handler.handleCallback(Handler.java:587)
    03-30 20:02:53.341: W/Bundle(17941):    at android.os.Handler.dispatchMessage(Handler.java:92)
    03-30 20:02:53.341: W/Bundle(17941):    at android.os.Looper.loop(Looper.java:130)
    03-30 20:02:53.341: W/Bundle(17941):    at android.app.ActivityThread.main(ActivityThread.java:3687)
    03-30 20:02:53.341: W/Bundle(17941):    at java.lang.reflect.Method.invokeNative(Native Method)
    03-30 20:02:53.341: W/Bundle(17941):    at java.lang.reflect.Method.invoke(Method.java:507)
    03-30 20:02:53.341: W/Bundle(17941):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
    03-30 20:02:53.341: W/Bundle(17941):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    03-30 20:02:53.341: W/Bundle(17941):    at dalvik.system.NativeStart.main(Native Method)
    03-30 20:02:53.353: W/Bundle(17941): Key message expected byte[] but value was a java.lang.String.  The default value <null> was returned.
    03-30 20:02:53.368: W/Bundle(17941): Attempt to cast generated internal exception:
    03-30 20:02:53.368: W/Bundle(17941): java.lang.ClassCastException: java.lang.String
    03-30 20:02:53.368: W/Bundle(17941):    at android.os.Bundle.getByteArray(Bundle.java:1305)
    03-30 20:02:53.368: W/Bundle(17941):    at com.facebook.android.Util.encodePostBody(Util.java:69)
    03-30 20:02:53.368: W/Bundle(17941):    at com.facebook.android.Util.openUrl(Util.java:188)
    03-30 20:02:53.368: W/Bundle(17941):    at com.facebook.android.Facebook.request(Facebook.java:751)
    03-30 20:02:53.368: W/Bundle(17941):    at com.dzinesunlimited.sociallyyou.StatusUpdate.postToWall(StatusUpdate.java:68)
    03-30 20:02:53.368: W/Bundle(17941):    at com.dzinesunlimited.sociallyyou.StatusUpdate$2.onClick(StatusUpdate.java:48)
    03-30 20:02:53.368: W/Bundle(17941):    at android.view.View.performClick(View.java:2538)
    03-30 20:02:53.368: W/Bundle(17941):    at android.view.View$PerformClick.run(View.java:9152)
    03-30 20:02:53.368: W/Bundle(17941):    at android.os.Handler.handleCallback(Handler.java:587)
    03-30 20:02:53.368: W/Bundle(17941):    at android.os.Handler.dispatchMessage(Handler.java:92)
    03-30 20:02:53.368: W/Bundle(17941):    at android.os.Looper.loop(Looper.java:130)
    03-30 20:02:53.368: W/Bundle(17941):    at android.app.ActivityThread.main(ActivityThread.java:3687)
    03-30 20:02:53.368: W/Bundle(17941):    at java.lang.reflect.Method.invokeNative(Native Method)
    03-30 20:02:53.368: W/Bundle(17941):    at java.lang.reflect.Method.invoke(Method.java:507)
    03-30 20:02:53.368: W/Bundle(17941):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
    03-30 20:02:53.368: W/Bundle(17941):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    03-30 20:02:53.368: W/Bundle(17941):    at dalvik.system.NativeStart.main(Native Method)
    03-30 20:02:53.368: W/Bundle(17941): Key method expected byte[] but value was a java.lang.String.  The default value <null> was returned.
    03-30 20:02:53.384: W/Bundle(17941): Attempt to cast generated internal exception:
    03-30 20:02:53.384: W/Bundle(17941): java.lang.ClassCastException: java.lang.String
    03-30 20:02:53.384: W/Bundle(17941):    at android.os.Bundle.getByteArray(Bundle.java:1305)
    03-30 20:02:53.384: W/Bundle(17941):    at com.facebook.android.Util.encodePostBody(Util.java:69)
    03-30 20:02:53.384: W/Bundle(17941):    at com.facebook.android.Util.openUrl(Util.java:188)
    03-30 20:02:53.384: W/Bundle(17941):    at com.facebook.android.Facebook.request(Facebook.java:751)
    03-30 20:02:53.384: W/Bundle(17941):    at com.dzinesunlimited.sociallyyou.StatusUpdate.postToWall(StatusUpdate.java:68)
    03-30 20:02:53.384: W/Bundle(17941):    at com.dzinesunlimited.sociallyyou.StatusUpdate$2.onClick(StatusUpdate.java:48)
    03-30 20:02:53.384: W/Bundle(17941):    at android.view.View.performClick(View.java:2538)
    03-30 20:02:53.384: W/Bundle(17941):    at android.view.View$PerformClick.run(View.java:9152)
    03-30 20:02:53.384: W/Bundle(17941):    at android.os.Handler.handleCallback(Handler.java:587)
    03-30 20:02:53.384: W/Bundle(17941):    at android.os.Handler.dispatchMessage(Handler.java:92)
    03-30 20:02:53.384: W/Bundle(17941):    at android.os.Looper.loop(Looper.java:130)
    03-30 20:02:53.384: W/Bundle(17941):    at android.app.ActivityThread.main(ActivityThread.java:3687)
    03-30 20:02:53.384: W/Bundle(17941):    at java.lang.reflect.Method.invokeNative(Native Method)
    03-30 20:02:53.384: W/Bundle(17941):    at java.lang.reflect.Method.invoke(Method.java:507)
    03-30 20:02:53.384: W/Bundle(17941):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
    03-30 20:02:53.384: W/Bundle(17941):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    03-30 20:02:53.384: W/Bundle(17941):    at dalvik.system.NativeStart.main(Native Method)
    03-30 20:02:53.388: W/Bundle(17941): Key access_token expected byte[] but value was a java.lang.String.  The default value <null> was returned.
    03-30 20:02:53.403: W/Bundle(17941): Attempt to cast generated internal exception:
    03-30 20:02:53.403: W/Bundle(17941): java.lang.ClassCastException: java.lang.String
    03-30 20:02:53.403: W/Bundle(17941):    at android.os.Bundle.getByteArray(Bundle.java:1305)
    03-30 20:02:53.403: W/Bundle(17941):    at com.facebook.android.Util.encodePostBody(Util.java:69)
    03-30 20:02:53.403: W/Bundle(17941):    at com.facebook.android.Util.openUrl(Util.java:188)
    03-30 20:02:53.403: W/Bundle(17941):    at com.facebook.android.Facebook.request(Facebook.java:751)
    03-30 20:02:53.403: W/Bundle(17941):    at com.dzinesunlimited.sociallyyou.StatusUpdate.postToWall(StatusUpdate.java:68)
    03-30 20:02:53.403: W/Bundle(17941):    at com.dzinesunlimited.sociallyyou.StatusUpdate$2.onClick(StatusUpdate.java:48)
    03-30 20:02:53.403: W/Bundle(17941):    at android.view.View.performClick(View.java:2538)
    03-30 20:02:53.403: W/Bundle(17941):    at android.view.View$PerformClick.run(View.java:9152)
    03-30 20:02:53.403: W/Bundle(17941):    at android.os.Handler.handleCallback(Handler.java:587)
    03-30 20:02:53.403: W/Bundle(17941):    at android.os.Handler.dispatchMessage(Handler.java:92)
    03-30 20:02:53.403: W/Bundle(17941):    at android.os.Looper.loop(Looper.java:130)
    03-30 20:02:53.403: W/Bundle(17941):    at android.app.ActivityThread.main(ActivityThread.java:3687)
    03-30 20:02:53.403: W/Bundle(17941):    at java.lang.reflect.Method.invokeNative(Native Method)
    03-30 20:02:53.403: W/Bundle(17941):    at java.lang.reflect.Method.invoke(Method.java:507)
    03-30 20:02:53.403: W/Bundle(17941):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
    03-30 20:02:53.403: W/Bundle(17941):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    03-30 20:02:53.403: W/Bundle(17941):    at dalvik.system.NativeStart.main(Native Method)
    03-30 20:02:53.403: W/Bundle(17941): Key format expected byte[] but value was a java.lang.String.  The default value <null> was returned.
    03-30 20:02:53.423: W/Bundle(17941): Attempt to cast generated internal exception:
    03-30 20:02:53.423: W/Bundle(17941): java.lang.ClassCastException: java.lang.String
    03-30 20:02:53.423: W/Bundle(17941):    at android.os.Bundle.getByteArray(Bundle.java:1305)
    03-30 20:02:53.423: W/Bundle(17941):    at com.facebook.android.Util.encodePostBody(Util.java:69)
    03-30 20:02:53.423: W/Bundle(17941):    at com.facebook.android.Util.openUrl(Util.java:188)
    03-30 20:02:53.423: W/Bundle(17941):    at com.facebook.android.Facebook.request(Facebook.java:751)
    03-30 20:02:53.423: W/Bundle(17941):    at com.dzinesunlimited.sociallyyou.StatusUpdate.postToWall(StatusUpdate.java:68)
    03-30 20:02:53.423: W/Bundle(17941):    at com.dzinesunlimited.sociallyyou.StatusUpdate$2.onClick(StatusUpdate.java:48)
    03-30 20:02:53.423: W/Bundle(17941):    at android.view.View.performClick(View.java:2538)
    03-30 20:02:53.423: W/Bundle(17941):    at android.view.View$PerformClick.run(View.java:9152)
    03-30 20:02:53.423: W/Bundle(17941):    at android.os.Handler.handleCallback(Handler.java:587)
    03-30 20:02:53.423: W/Bundle(17941):    at android.os.Handler.dispatchMessage(Handler.java:92)
    03-30 20:02:53.423: W/Bundle(17941):    at android.os.Looper.loop(Looper.java:130)
    03-30 20:02:53.423: W/Bundle(17941):    at android.app.ActivityThread.main(ActivityThread.java:3687)
    03-30 20:02:53.423: W/Bundle(17941):    at java.lang.reflect.Method.invokeNative(Native Method)
    03-30 20:02:53.423: W/Bundle(17941):    at java.lang.reflect.Method.invoke(Method.java:507)
    03-30 20:02:53.423: W/Bundle(17941):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
    03-30 20:02:53.423: W/Bundle(17941):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    03-30 20:02:53.423: W/Bundle(17941):    at dalvik.system.NativeStart.main(Native Method)

非常感谢任何帮助。

最佳答案

很好很好很好。我觉得自己完全是个白痴,因为我忽略了重要的警告……:-(

诀窍是在第 69 行更改 Facebook SDK 中的 Util.java:

if (parameters.getByteArray(key) != null) {

到:

if (parameters.get(key) instanceof byte[]) {

感谢此处发布的解决方案:https://stackoverflow.com/a/3927541/450534

关于Android Facebook 贴在墙上没有对话框警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9945153/

相关文章:

facebook-graph-api - Facebook Graph Api——我可以得到 "default"字段加上一些吗?

java - Android 应用程序在多次回调后变得缓慢 - 这里出了什么问题?

facebook-graph-api - FQl和Graph API:有没有一种方法可以在页面墙中获取“hidden posts”(提要/流)

Android模拟器系统分区从一开始就没有空间

android - 构建 Python 包成功,但 Scikit-learn 构建不正确

Facebook:如何将共享者设为弹出窗口

css - 社交分享按钮定位

java - 谷歌地方 API : refresh Place IDs with Java

android - 如何在不反转所选项目的情况下从左到右反转微调器?

ios - Facebook SDK 3.2 登录仅在应用程序未终止时才有效