[英]FeedDialog in android facebook sdk does not work
我正在尝试使用FeedDialog在Facebook上发布消息。
参考: http : //developers.facebook.com/docs/howtos/androidsdk/3.0/feed-dialog/
码:
private void publishFeedDialog(){
Bundle params = new Bundle();
params.putString("name", "Facebook SDK for Android");
params.putString("caption", "Build great social apps and get more installs.");
params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
FeedDialogBuilder builder = new FeedDialogBuilder(getActivity(), Session.getActiveSession(), params);
builder.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
if (error != null) {
Log.d(TAG, "FeedDialog Error : "+error.getMessage());
}
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getActivity(),"Posted story, id: "+postId,Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(getActivity().getApplicationContext(), "Publish cancelled",Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getActivity().getApplicationContext(), "Publish cancelled", Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(getActivity().getApplicationContext(), "Error posting story",Toast.LENGTH_SHORT).show();
}
}
});
builder.build().show();
}
按钮onClickListener:
publishButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
publishFeedDialog();
}
});
当我单击“发布”按钮时,显示一个等待对话框,一段时间后该对话框Toast
,我Toast
说"Error posting story"
,为什么?
logcat的
D/FacebookSDK.WebDialog(3572): Webview loading URL:
当我在浏览器中打开上面的链接时,它会工作并显示“张贴到墙上”对话框,例如
D/MainFragment(3150): {Response: responseCode: unknown, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: null}, isFromCache:false}
D/MainFragment(3150): FeedDialog Error : Couldn't find the URL.
这是来自Facebook开发人员页面,我已经用过了。 就我而言,它有效。 你应该尝试这样:
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("name", "Facebook SDK for Android");
params.putString("caption", "Build great social apps and get more installs.");
params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(getActivity(),
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values,
FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getActivity(),
"Posted story, id: "+postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(getActivity().getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getActivity().getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(getActivity().getApplicationContext(),
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
})
.build();
feedDialog.show();
}
仔细看看这部分:
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(getActivity(),
但是你用过
FeedDialogBuilder builder = new FeedDialogBuilder(getActivity(),
我认为问题就在这里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.