使用Facebook sdk 3.1发布到Facebook页面墙的链接

问题描述 投票:2回答:2

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

我尝试过使用pageid / feed发布。但是,即使它是由页面所有者发布的,它也显示在“其他人在页面名上的最新帖子”标签下。我需要在页面的墙上显示它。用于在页面上发布的代码如下

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();
android facebook
2个回答
3
投票

要发布到Page wall,会话值应该为null,并将页面的access_token添加为post参数。

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();

-1
投票

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

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

完整样本

HelloFacebookSample:一个全面的示例,演示了配置文件访问,状态更新和照片上传

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

© www.soinside.com 2019 - 2024. All rights reserved.