gpt4 book ai didi

android - Facebook 请求不等待用户输入

转载 作者:行者123 更新时间:2023-11-29 22:08:07 26 4
gpt4 key购买 nike

我正在编写一个可以根据用户行为在 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();
}
}

最佳答案

您正在使用 facebook.request() 方法,它会在后台静默发布您的消息。要显示对话框,您将使用 facebook.dialog() 方法。您的代码将如下所示:

facebook.dialog(context, "stream.publish", parameters, new SomeDialogListener());

SomeDialogListenerDialogListener 的子类,将是您处理来自 facebook 的响应的回调实例(与登录对话框的情况相同).

关于android - Facebook 请求不等待用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10295770/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com