我已经从github下载并设置了 android simple facebook sdk 。我制作了一个简单的页面来测试发布提要,并且能够添加消息并单击“共享”。但是,一旦我单击共享,就会出现一个进度对话框,上面写着“正在发送...”,然后它就消失了,但没有发送任何内容。我打印了错误消息,它只是说“被用户取消”。
这是我的代码,它只是一个登录按钮,成功后会尝试发布提要。
Button postStuff;
private UiLifecycleHelper uiHelper;
Permission[] permissions = new Permission[] {
Permission.USER_PHOTOS,
Permission.EMAIL,
Permission.PUBLISH_ACTION
};
SimpleFacebookConfiguration configuration = new SimpleFacebookConfiguration.Builder()
.setAppId("My-App-ID")
.setNamespace("my_namespace")
.setPermissions(permissions)
.build();
SimpleFacebook mSimpleFacebook;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.fbtest);
SimpleFacebook.setConfiguration(configuration);
postStuff = (Button) findViewById(R.id.postStuff);
postStuff.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
OnLoginListener onLoginListener = new OnLoginListener() {
@Override
public void onLogin() {
// change the state of the button or do whatever you want
Log.i("fb login", "Logged in");
OnPublishListener onPublishListener = new OnPublishListener() {
@Override
public void onComplete(String postId) {
Log.i("fb post", "Published successfully. The new post id = " + postId);
}
@Override
public void onFail(String reason) {
Log.i("fb post","failed: " + reason);
}
/*
* You can override other methods here:
* onThinking(), onFail(String reason), onException(Throwable throwable)
*/
};
Feed feed = new Feed.Builder()
.setMessage("Check this out.")
.setName("Home Shop Guide App for Android")
.setCaption("Win prizes and deals daily")
.setDescription("User just won $500 from a daily scratchoff prize. You could be the next winner!")
.setPicture("https://homeshopguide.com/images/logo.png")
.setLink("https://homeshopguide.com/")
.build();
mSimpleFacebook.publish(feed, true, onPublishListener);
}
@Override
public void onNotAcceptingPermissions(Permission.Type type) {
// user didn't accept READ or WRITE permission
Log.w("fb login", String.format("You didn't accept %s permissions", type.name()));
}
@Override
public void onThinking() {
// TODO Auto-generated method stub
Log.i("fb login", "thinking");
}
@Override
public void onException(Throwable throwable) {
// TODO Auto-generated method stub
Log.i("fb login", "exception" + throwable.getLocalizedMessage());
}
@Override
public void onFail(String reason) {
// TODO Auto-generated method stub
Log.i("fb login", "failed: " + reason);
}
};
mSimpleFacebook.login(onLoginListener);
}
});
}
@Override
public void onResume() {
super.onResume();
mSimpleFacebook = SimpleFacebook.getInstance(this);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mSimpleFacebook.onActivityResult(this, requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}
这就是我按下按钮时错误日志中显示的内容:
03-19 17:01:53.537: I/fb login(31226): Logged in
03-19 17:01:53.647: D/OpenGLRenderer(31226): Flushing caches (mode 1)
03-19 17:01:53.957: D/OpenGLRenderer(31226): Flushing caches (mode 0)
03-19 17:02:05.527: I/fb post(31226): failed: Canceled by user
编辑: 第二天我再次尝试(在进行任何更改之前),日志显示帖子成功。但是,我用来开发的 facebook 帐户是一个商业帐户,我不知道提要发布到哪里。
正如 sromku 建议的那样,我将应用程序置于实时模式以使用普通的 Facebook 帐户进行测试。我仍然收到“用户取消”错误。但是,当我检查我的墙时,帖子正如预期的那样在那里。我现在的问题是我做错了什么来收到这个错误,或者它只是一个不应该出现的错误。