我正在编写一个可以按照用户行为在 Facebook 上发布的应用程序。发布的过程是点击 FB 按钮,接下来发生的事情是 Facebook 尝试登录,如果用户已经登录,使用 SSO,它会创建一个 Facebook 对话框并将其发布到用户提要.
但是,没有与用户交互,并且帖子按原样发布在 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();
}
}