2013-02-26 61 views
2

我正在嘗試在Facebook牆上發佈消息而沒有使用Facebook Android SDK打開對話框。我試圖找到一種方式,但找不到。任何人都可以告訴他們如何在沒有打開對話的情況下發布到後臺。在Facebook上顯示的牆上未顯示android上的對話框

我嘗試使用下面的代碼

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

什麼是您的發佈參數? – 2013-02-26 16:52:53

+0

_postParameters_是一個包含消息,圖片鏈接,頁面鏈接等的包 – glo 2013-02-27 03:54:07

+0

我的意思是,請提供一個示例,說明您在postParameters(包含代碼)中放入的內容以及它實際發佈到牆上的內容。這樣我們可以看,也可以指出任何錯誤。您當前的代碼示例太簡潔,無法真正調試。 – 2013-02-27 05:55:18

回答

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

據我所知,這是可能與REST API,它現在已不... https://developers.facebook.com/docs/reference/rest/

編輯:這裏是功能,您可以使用發佈https://developers.facebook.com/docs/reference/rest/#publishing-methods

+1

可以請你提供一個例子 – glo 2013-02-27 03:53:02

+0

我試過使用下面的方法,但也沒有工作Request.executeRestRequestAsync(Session.getActiveSession(),「stream.publish」,_postParameter,HttpMethod.POST) ;' – glo 2013-02-27 05:40:03

+0

我認爲所有的發佈行爲只能在'Dialog'內完成 – thepoosh 2013-02-27 06:37:33