我已经从github下载并设置了android简单的facebook sdk。我已经做了一个简单的页面来测试发布一个feed,我能够达到可以添加消息并单击“share”的程度。但是,一旦我点击共享,就会出现一个进度对话框,上面写着“发送......”然后就会消失但是没有发送任何内容。我打印了错误消息,它只是说“用户取消”。
以下是我的代码,它只是一个登录按钮,成功时会尝试发布Feed。
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帐户进行测试。我仍然收到“用户取消”错误。然而,当我检查我的墙时,帖子就像预期的那样。我现在的问题是我做错了什么来接收这个错误,或者只是当它不应该出现时出现错误。