[英]Share post to multiple friends with Facebook SDK 3.0+ - Android
[英]Share link and text with Android Facebook SDK 3.0
我试图升级到Facebook SDK 3.0,并最终得到一切与Request.newStatusUpdateRequest()。 但是,我的应用程序共享/发布文本以及链接。 我试过/研究过以下内容:
Request.newStatusUpdateRequest()
这似乎没有Bundle的任何选项或任何其他方式来包含链接和图标。
Request.newRestRequest()
跳过这个因为我看到REST被折旧了。
new WebDialog.FeedDialogBuilder(_activity, session, params).build().show();
这实际上工作得很好,但结果的帖子似乎没有链接到我的Facebook应用程序,我不知道这将如何影响我的Facebook见解。
Request.newPostRequest()
从我所读到的,这种方法似乎是正确的方法。 但是,我无法弄清楚将GraphObject作为参数之一传入的位置。
什么是将文本,链接和图像发布/共享到用户墙上的PROPPER方式? 它似乎是Request.newPostRequest()所以我将包含我的代码。
Request request = Request.newPostRequest(session, "me/feed", ??graph_object??, new Request.Callback() {
@Override
public void onCompleted(Response response) {
showPublishResult("message", response.getGraphObject(), response.getError());
}
});
request.setParameters(params);
Request.executeBatchAsync(request);
但究竟什么是GraphObject? 我在哪里获得graph_object? 我在GraphObject / OpenGraph / Graph API上从FB读取的越多,我就越感到困惑。
如果我完全朝着错误的方向前进,请告诉我。 如果Request.newPostRequest是执行此操作的方式,请提供有关GraphObject参数的更多信息。
最后使用以下方法设法通过Facebook SDK 3.0获得我需要的一切:
Bundle params = new Bundle();
params.putString("caption", "caption");
params.putString("message", "message");
params.putString("link", "link_url");
params.putString("picture", "picture_url");
Request request = new Request(Session.getActiveSession(), "me/feed", params, HttpMethod.POST);
request.setCallback(new Request.Callback() {
@Override
public void onCompleted(Response response) {
if (response.getError() == null) {
// Tell the user success!
}
}
});
request.executeAsync();
我用这种方法做了。 看看这是否有帮助。
public static void publishFeedDialog(final Activity current, final String title,
final String caption, final String description, final String link,
final String pictureUrl) {
// start Facebook Login
Session.openActiveSession(current, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state,
Exception exception) {
if (session.isOpened()) {
Bundle params = new Bundle();
params.putString("name", title);
params.putString("caption", caption);
params.putString("description", description);
params.putString("link", link);
params.putString("picture", pictureUrl);
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(
current, 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) {
ToastHelper.MakeShortText("Posted");
} else {
// User clicked the Cancel button
ToastHelper
.MakeShortText("Publish cancelled");
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
ToastHelper
.MakeShortText("Publish cancelled");
} else {
// Generic, ex: network error
ToastHelper
.MakeShortText("Error posting story");
}
}
}).build();
feedDialog.show();
}
}
});
分享页面或链接
Bundle params = new Bundle();
params.putString("link", "link_url");
Request request = new Request(Session.getActiveSession(), "me/feed", params, HttpMethod.POST);
request.setCallback(new Request.Callback() {
@Override
public void onCompleted(Response response) {
if (response.getError() == null) {
// Tell the user success!
}
}
});
request.executeAsync();
有关更多帖子参数,请参阅developer.facebook.com上的me / feed
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.