我正在编写一个可以在用户的行为上发布在Facebook上的应用程序。 发布的过程是单击FB按钮,接下来发生的事情是Facebook尝试登录,如果用户已经登陆,使用SSO,它会创建一个Facebook对话框并发布它在用户Feed上。
但是,没有与用户互动,帖子正在Facebook上发布。
如何提示常规移动应用用户互动以便在Facebook上发布?
登录Facebook的代码:
public static final String appid = "1234567890";
public static final String[] permissions = { "publish_stream" };
Facebook facebook;
facebook.authorize(MyClass.this, permissions,
new DialogListener() {
@Override
public void onComplete(Bundle values) {
// control comes here if the login was successful
// Facebook.TOKEN is the key by which the value of
// access token is stored in the Bundle called
// 'values'
Log.d("COMPLETE", "AUTH COMPLETE. VALUES: "
+ values.size());
Log.d("AUTH TOKEN",
"== " + values.getString(Facebook.TOKEN));
updateStatus(values.getString(Facebook.TOKEN));
}
@Override
public void onFacebookError(FacebookError e) {
Log.d("FACEBOOK ERROR", "FB ERROR. MSG: " + e.getMessage()
+ ", CAUSE: " + e.getCause());
}
@Override
public void onError(DialogError e) {
Log.e("ERROR", "AUTH ERROR. MSG: " + e.getMessage()
+ ", CAUSE: " + e.getCause());
}
@Override
public void onCancel() {
Log.d("CANCELLED", "AUTH CANCELLED");
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("onActivityResult", "onActivityResult");
facebook.authorizeCallback(requestCode, resultCode, data);
}
publishStream()
的代码:
protected void updateStatus(String accessToken) {
try {
Bundle msg = new Bundle();
msg.putString("description", this.title);
msg.putString("link", this.link);
msg.putString("message", description);
msg.putString(Facebook.TOKEN, accessToken);
String response = facebook.request("me/feed", msg, "POST");
Log.d("UPDATE RESPONSE", "" + response);
Toast.makeText(SinglePost.this, "Posted on Facebook", Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
答案 0 :(得分:2)
您正在使用facebook.request()
方法,它会在后台静默发布您的消息。要显示对话框,您将使用facebook.dialog()
方法。您的代码将如下所示:
facebook.dialog(context, "stream.publish", parameters, new SomeDialogListener());
其中SomeDialogListener
是DialogListener
的子类,并且将成为处理来自facebook
的响应的回调实例(与登录对话框的情况相同)。