![](/img/trans.png)
[英]Embed link in message field of Facebook post using Facebook sdk 3.1
[英]Post a link to wall of Facebook page using Facebook sdk 3.1
如何使用 Facebook sdk 3.1 在 Android 应用程序的页面时间轴/墙上发布链接。
我尝试使用 pageid/feed 发帖。 但它显示在标签“其他人在pagename上最近的帖子”下,即使它是由页面所有者发布的。我需要在页面的墙上显示它。用于在页面上发布的代码如下
Bundle postParams = new Bundle();
postParams.putString("message","message");
postParams.putString("name","name");
postParams.putString("link",link);
postParams.putString("picture",picture);
postParams.putString("display", "page");
Request.Callback callback = new Request.Callback() {
public void onCompleted(Response response) {
FacebookRequestError error = response.getError();
if (error != null) {
Log.e("FACEBOOK ERROR", ""+ error.getErrorMessage());
} else {
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
String postId = null;
try {
postId = graphResponse
.getString("id");
} catch (JSONException e) {
}
}
}
};
Request request = new Request(session,pageid+"/feed",postParams, HttpMethod.POST,callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
要发布到页面墙,会话值应为空并将页面的 access_token 添加为发布参数。
Bundle postParams = new Bundle();
postParams.putString("message","message");
postParams.putString("name","name");
postParams.putString("link",link);
postParams.putString("picture",picture);
postParams.putString("access_token", pageaccessToken);
Request.Callback callback = new Request.Callback() {
public void onCompleted(Response response) {
FacebookRequestError error = response.getError();
if (error != null) {
Log.e("FACEBOOK ERROR", ""+ error.getErrorMessage());
} else {
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
String postId = null;
try {
postId = graphResponse
.getString("id");
} catch (JSONException e) {
}
}
}
};
Request request = new Request(null,pageid+"/feed",postParams, HttpMethod.POST,callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
本指南向您展示如何开始使用Facebook SDK for Android 进行开发。
https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/
完整的样品
HelloFacebookSample
:一个全面的示例,演示个人资料访问、状态更新和照片上传
Scrumptious
: 演示使用登录、请求、选择器、图片上传和开放图谱发布
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.