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

glo*_*glo 2 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();
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

但它发布我的应用页面详细信息而不是*_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());
       }
   });
Run Code Online (Sandbox Code Playgroud)

第二种方法是

Request.executeRestRequestAsync(Session.getActiveSession(), "stream.publish", _postParameter, HttpMethod.POST);
Run Code Online (Sandbox Code Playgroud)

glo*_*glo 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();
    }
});
}
Run Code Online (Sandbox Code Playgroud)