发布在Facebook墙上没有在Android上显示对话框

时间:2013-02-26 14:28:04

标签: android facebook facebook-graph-api facebook-rest-api

我正在尝试在Facebook墙上发布Feed,而无需使用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 *我给。

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

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

2 个答案:

答案 0 :(得分: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();
    }
});
}

答案 1 :(得分:0)

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

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

的功能