2

我正在尝试在 Facebook 墙上发布提要,而无需使用 Facebook Android SDK 打开对话框。我试图找到一种方法,但找不到。谁能告诉他们如何在不打开对话的情况下在后台发帖。

我尝试使用下面的代码

public static void PublishToFeedInBackground()
{
     final Bundle _postParameter = new Bundle();
     _postParameter.putString("name", name);
     _postParameter.putString("link", link);
     _postParameter.putString("picture", link_to_image);
     _postParameter.putString("caption", caption);
     _postParameter.putString("description", description);

     final List<String> PERMISSIONS = Arrays.asList("publish_actions");

     if (Session.getActiveSession() != null)
     {
            // Check for publish permissions    
            List<String> _permissions = Session.getActiveSession().getPermissions();
            if (!isSubsetOf(PERMISSIONS, _permissions))
            {
                NewPermissionsRequest reauthRequest = new Session.NewPermissionsRequest(this.GetContext(), PERMISSIONS);
                Session.getActiveSession().requestNewReadPermissions(reauthRequest);
                return;
            }   
     }

    this.runOnUiThread(new Runnable()
    {
        @Override
        public void run() 
        {
            Request request = new Request(Session.getActiveSession(), "me/feed", _postParameter, HttpMethod.POST);

            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();
        }
    });
}

但它会发布我的应用页面详细信息,而不是我提供的 *_postParameter*。

我也尝试使用其他 2 种方法,但它没有发布任何内容

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("name", name);
    params.put("link", link);
    params.put("picture", link_to_image);
    params.put("caption", caption);
    params.put("description", description);

    JSONObject jfeed = new JSONObject(params);
    final GraphObject _feed = GraphObject.Factory.create(jfeed);

    Request.executePostRequestAsync(Session.getActiveSession(), "https://graph.facebook.com/"+userID+"/feed", _feed, new Request.Callback()
    {
       @Override
       public void onCompleted(Response response) 
       {
            Log.i("tag", response.toString());
       }
   });

第二种方法是

Request.executeRestRequestAsync(Session.getActiveSession(), "stream.publish", _postParameter, HttpMethod.POST);
4

2 回答 2

5

我发现了问题所在。我没有要求正确的权限,并且图形路径也是错误的。正确的方法是:

public static void PublishToFeedInBackground()
{

final Bundle _postParameter = new Bundle();
 _postParameter.putString("name", name);
 _postParameter.putString("link", link);
 _postParameter.putString("picture", link_to_image);
 _postParameter.putString("caption", caption);
 _postParameter.putString("description", description);

     final List<String> PERMISSIONS = Arrays.asList("publish_stream");

 if (Session.getActiveSession() != null)
 {
       NewPermissionsRequest reauthRequest = new Session.NewPermissionsRequest(this.GetContext(), PERMISSIONS);
        Session.getActiveSession().requestNewPublishPermissions(reauthRequest);
 }

this.runOnUiThread(new Runnable()
{
    @Override
    public void run() 
    {
        Request request = new Request(Session.getActiveSession(), "feed", _postParameter, HttpMethod.POST);

        RequestAsyncTask task = new RequestAsyncTask(request);
        task.execute();
    }
});
}
于 2013-02-27T10:00:41.690 回答
0

据我所知,这可以通过现在已弃用的 REST api 实现...... https://developers.facebook.com/docs/reference/rest/

编辑:这里是您可以用来发布https://developers.facebook.com/docs/reference/rest/#publishing-methods的功能

于 2013-02-26T15:22:50.213 回答