我认为,这是一个非常简单的问题。我的应用程序中有一个按钮。如果我点击它,它执行一种方法。在这种方法中,我想在用户的Facebook墙上分享“嗨,这是使用xxxxx产品的xxx”消息。我怎样才能做到这一点?有没有教程?
myMethod(){
//share on fb wall
}
答案 0 :(得分:0)
来自Sharing in Android教程:
先决条件
在您可以通过应用分享到Facebook或尝试关注之前 任何共享教程,您将需要:
您的环境设置正确配置和链接的Facebook应用 启用SSO到您的Android应用程序Facebook SDK添加到您的 项目如果你没有这样做并需要帮助,你可以 关注我们的getting started guide。
然后,基本上,让你的myMethod
称之为:
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();
}