[英]Oauth error message “Missing message or attachment”, “type”:“OAuthException”,“code”:100 in android while Facebook post on friends wall
我想给我的应用程序用户一个使用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应用程序。 为此,我正在尝试通过此链接编写代码, 向Facebook朋友发送邀请以加入我的网站 ,并修改了它的代码(因为它不起作用),现在的代码是:
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}}
因此,请帮助我删除此错误。
为什么将params.putByteArray
用于文本字段? 我了解“图片”字段。 但是,一个简单的params.putString
满足“消息”,“链接”,“标题”,“描述”和“名称”字段。
另外,您要两次传递“ message”参数。 曾经在这里: 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());
我只上传来自图库或相机的照片。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.