【问题标题】:Oauth error message "Missing message or attachment", "type":"OAuthException","code":100 in android while Facebook post on friends wallOauth 错误消息“缺少消息或附件”,“类型”:“OAuthException”,“代码”:Android 中的 100,而 Facebook 在朋友墙上发帖
【发布时间】:2012-11-21 01:30:17
【问题描述】:

我想为我的应用程序用户提供使用 Facebook 帐户登录我的应用程序的选项。我可以使用下面的代码来做到这一点。

String[] permissions = { "offline_access", "publish_stream", "user_photos", "publish_checkins", "photo_upload" };
mFacebook.authorize(FacebookLogin.this, permissions, new LoginDialogListener());

public final class LoginDialogListener implements DialogListener {
    public void onComplete(Bundle values) {
        new MyAsyncGetJsonFromFacebbok(FacebookLogin.this).execute();
    }

    public void onFacebookError(FacebookError error) {
        Toast.makeText(FacebookLogin.this, "Something went wrong. Please try again.", Toast.LENGTH_LONG).show();
        Log.v("onFacebookError FacebookLogin", error.toString());
    }

    public void onError(DialogError error) {
        Toast.makeText(FacebookLogin.this, "Something went wrong. Please try again.", Toast.LENGTH_LONG).show();
        Log.v("onError FacebookLogin", error.toString());
    }

    public void onCancel() {
        Toast.makeText(FacebookLogin.this, "Something went wrong. Please try again.", Toast.LENGTH_LONG).show();
    }

    public class MyAsyncGetJsonFromFacebbok extends AsyncTask<Void, Void, JSONObject> {
        Context context;
        JSONObject jsonObj = null;

        public MyAsyncGetJsonFromFacebbok(Context context_) {
            this.context = context_;
        }

        @Override
        protected JSONObject doInBackground(Void... params) {
            try {
                jsonObj = com.facebook.android.Util.parseJson(mFacebook.request("me"));
            } catch (FacebookError e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return jsonObj;
        }

        @Override
        protected void onPostExecute(JSONObject jsonObj) {
            try {
                String facebookID = jsonObj.getString("id");
                String firstName = jsonObj.getString("first_name");
                String lastName = jsonObj.getString("last_name");
                Toast.makeText(FacebookLogin.this, "Thank you for Logging In, " + firstName + " " + lastName + "!", Toast.LENGTH_SHORT)
                        .show();
                SessionStore.save(mFacebook, FacebookLogin.this);
                storeDataInSharedPreferrence(facebookID, firstName, lastName);
                sendInvitationToFriends(facebookID);
                startNextActivity();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

现在我正在尝试邀请我所有的 Facebook 朋友加入我的 Android 应用程序。为此,我正在尝试此链接中的代码send an invitation to facebook friends to join my website,并修改了它的代码(因为它不起作用),现在代码是:

String response = mFacebook.request((userID == null) ? "me" : userID);
            Bundle params = new Bundle();

            params.putString("message", "msg");
            params.putString(mFacebook.getAccessToken(), "msg");

            params.putByteArray("message", "message goes here".getBytes());
            params.putByteArray("link", "http://mysite.com".getBytes());
            params.putByteArray("caption", "Click the link".getBytes());
            params.putByteArray("description", "description of link".getBytes());
            params.putByteArray("name", "name of link".getBytes());
            params.putByteArray("picture", "http://url.to.my.picture/pic.jpg".getBytes());

            response = mFacebook.request(((userID == null) ? "me" : userID) + "/feed", params, "POST");

但它给出了错误

12-03 19:46:04.552: D/Tests(873): {"error":{"message":"(#100) Missing message or attachment","type":"OAuthException","code":100}}

所以请帮我消除这个错误。

【问题讨论】:

    标签: android facebook oauth friend invitation


    【解决方案1】:

    您为什么将params.putByteArray 用于文本字段?我了解“图片”字段。但是一个简单的params.putString 就足够了“消息”、“链接”、“标题”、“描述”和“名称”字段。

    另外,您传递了两次“消息”参数。 到过这里:params.putString("message", "msg");

    另一个在这里:params.putByteArray("message", "message goes here".getBytes());

    您的代码基本上应该如下所示:

    Bundle params = new Bundle();
    params.putString("message", "msg");
    params.putString(mFacebook.getAccessToken(), "msg");
    
    params.putString("message", "message goes here".getBytes()); // CHOOSE FROM EITHER THE ONE ON THIS LINE OR THIS ONE: params.putString("message", "msg");
    params.putString("link", "http://mysite.com".getBytes());
    params.putString("caption", "Click the link".getBytes());
    params.putString("description", "description of link".getBytes());
    params.putString("name", "name of link".getBytes());
    params.putByteArray("picture", "http://url.to.my.picture/pic.jpg".getBytes());
    

    我为我的应用程序使用完全相同的代码(嗯,几乎无论如何),它工作得很好。话虽如此,我不太确定这个:params.putByteArray("picture", "http://url.to.my.picture/pic.jpg".getBytes());

    我只从图库或相机上传照片。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-29
      • 2012-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多