Android OAutheException在尝试发布到好友墙时
我在安卓系统中使用Facebook api向朋友墙发帖时遇到了很多麻烦。这就是我目前的情况:Android OAutheException在尝试发布到好友墙时,android,facebook,Android,Facebook,我在安卓系统中使用Facebook api向朋友墙发帖时遇到了很多麻烦。这就是我目前的情况: if (facebook.isSessionValid()) { String response = facebook.request((userID == null) ? "me" : userID); Bundle params = new Bundle();
if (facebook.isSessionValid()) {
String response = facebook.request((userID == null) ? "me" : userID);
Bundle params = new Bundle();
params.putString("message", "put message here");
params.putString("link", "http://mylink.com");
params.putString("caption", "{*actor*} just posted this!");
params.putString("description", "description of my link. Click the link to find out more.");
params.putString("name", "Name of this link!");
params.putString("picture", "http://mysite.com/picture.jpg");
response = facebook.request(((userID == null) ? "me" : userID) + "/feed", params, "POST");
Log.d("Tests",response);
if (response == null || response.equals("") ||
response.equals("false")) {
Log.v("Error", "Blank response");
}
} else {
// no logged in, so relogin
Log.d("1234567890", "sessionNOTValid, relogin");
}
}catch(Exception e){
e.printStackTrace();
}
但这会返回以下错误:
12-11 21:34:06.604: D/FACEBOOK RESPONSE(14954): {"error":{"message":"(#200) Feed story publishing to other users is disabled for this application","type":"OAuthException","code":200}}
您可能最近创建了此Facebook应用程序,这意味着2013年2月的突破性更改已启用 包括: 删除通过Graph API发布到朋友墙的功能 我们将取消通过Graph API发布到用户朋友墙上的功能。具体来说,如果[user\u id]与会话用户不同,则针对[user\u id]/feed的POST,或者目标用户与会话用户不同的stream.publish调用将失败。如果您想允许人们发布到朋友的时间线,请调用提要对话框。通过用户提及标记或动作标记包含朋友的故事将显示在朋友的时间线上(假设朋友批准标记)。有关更多信息,请参阅此博客文章 我们将从2月开始禁用此功能,如果您希望启用此功能(仅在2月之前暂时启用),请转到您的应用程序仪表板>设置>高级>禁用“2013年2月的重大更改”
但是,我强烈建议您不要这样做,因为从2月份开始,此功能将导致您的应用程序再次抛出相同的错误。我有一个解决方案可以帮助您,我将此用于我的代码,并且工作正常 私有void publishFeedDialog(字符串friend\u uid){
此代码仅适用于一个用户,如果要将其发送给多个用户,则可以使用RequestsDialogBuilder而不是WebDialog。是否设置了适当的权限?这些是我设置的权限:“新建字符串[]{”发布\u流,发布\u操作,读取\u流“}”还有,关于stackoverflow的评论目前还不能正常工作。我收到一个通知说“看不到任何;)”但是这里没有提到。啊,非常感谢!你知道我将如何制作一个包含另一个用户的故事吗?最好的方法是在Bundle中使用
to
参数和朋友的UID调用提要对话框(应该可以)。或者,您可以发布带有用户提及标记的定期状态更新,以便显示在朋友的时间线上。@JesseChen您可以告诉我如何使用facebookmobile API标记朋友吗?谢谢!我必须测试它。我收到一个对话框,消息为“无法发布到用户墙”。请参考链接
try{
Session mCurrentSession = Session.getActiveSession();
SessionTracker mSessionTracker = new SessionTracker(
getBaseContext(), new StatusCallback() {
public void call(Session session, SessionState state,
Exception exception) {
}
}, null, false);
String applicationId = Utility
.getMetadataApplicationId(getBaseContext());
mCurrentSession = mSessionTracker.getSession();
if (mCurrentSession == null
|| mCurrentSession.getState().isClosed()) {
mSessionTracker.setSession(null);
Session session = new Session.Builder(getBaseContext())
.setApplicationId(applicationId).build();
Session.setActiveSession(session);
mCurrentSession = session;
}
if (!mCurrentSession.isOpened()) {
Session.OpenRequest openRequest = null;
openRequest = new Session.OpenRequest(
NewFriendList.this);
if (openRequest != null) {
openRequest
.setDefaultAudience(SessionDefaultAudience.FRIENDS);
openRequest.setPermissions(Arrays.asList("email", "publish_actions"));
openRequest
.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
mCurrentSession.openForPublish(openRequest);
}
}
if (regobj != null && friend_uid != null ) {
final Activity activity = this;
Bundle params = new Bundle();
//This is what you need to post to a friend's wall
params.putString("from", "" + regobj.MyFBID);
params.putString("to", friend_uid);
//up to this
params.putString("name", "Facebook SDK for Android");
params.putString("caption", "Build great social apps and get more installs.");
params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(this, mCurrentSession, params))
.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(activity,
"Posted story, id: "+postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(activity,
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(activity,
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(activity,
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
}).build();
feedDialog.show();
}
}catch(Exception e)
{
Log.d("Error", ""+e.toString());
}
}