2

如何使用 Facebook sdk 3.1 从 Android 应用程序在页面的时间线/墙上发布链接。

我尝试使用 pageid/feed 发布。但是即使它是由页面所有者发布的,它也会显示在标签“Recent Posts By Others on 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();
4

2 回答 2

3

对于发布到页面墙,会话值应为 null,并将页面的 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();
于 2013-06-24T10:28:18.007 回答
-1

本指南向您展示如何开始使用Facebook SDK for Android进行开发。

https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/

完整的样品

HelloFacebookSample: 一个全面的示例,演示个人资料访问、状态更新和照片上传

Scrumptious:演示登录、请求、选择器、图片上传和Open Graph发布的使用

于 2013-06-11T09:24:31.560 回答