我希望能够在我的Android应用程序中从后台无缝发布到用户的Facebook Feed。用户完全了解他们发布的内容,但是在相对较长的上传过程之后将发布帖子,因此不应让用户等待。我正在使用Android Facebook SDK v4.1.2。
我发现我需要事先向用户请求"publish_actions"
权限:
https://developers.facebook.com/docs/facebook-login/permissions/v2.3#reference-publish_actions
我可以使用LoginManager
获取访问令牌:
https://developers.facebook.com/docs/facebook-login/android/v2.3#access_profile
我不知道如何在不使用ShareDialog
的情况下分享指向用户Feed的链接:
https://developers.facebook.com/docs/sharing/android
这个SO question建议使用v3.x的Request
对象,这相当于v4.x的GraphRequest
对象:
https://developers.facebook.com/docs/reference/android/current/class/GraphRequest/
但我不确定如何构建正确的GraphRequest
。我假设我需要向"/me/feed"
发布消息:
https://developers.facebook.com/docs/graph-api/reference/v2.3/user/feed
谁能告诉我怎么做?
答案 0 :(得分:2)
在撰写问题时,我通过拖网文档和示例找到了自己的解决方案。我需要向"/me/feed"
发布消息:
https://developers.facebook.com/docs/graph-api/reference/v2.3/user/feed
Bundle params = new Bundle();
params.putString("link", link);
GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(),
"/me/feed", params, HttpMethod.POST,
new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
}
});
request.executeAndWait();
获得"publish_actions"
权限后。
答案 1 :(得分:1)
如果您不想自己构建params包,则应使用ShareApi类。
像往常一样构建ShareLinkContent:
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("https://your.url.com"))
.build();
然后致电ShareApi:
ShareApi.share(content, new FacebookCallback<Sharer.Result>() {...});