2011-10-10 73 views
-1

下面的代碼似乎只是發佈'消息',沒有別的。有什麼我失蹤? (使用Facebook的Android SDK)Facebook發佈到Android上的牆上,只有消息

parameters.putString("link", link); 
parameters.putString("description", description); 
parameters.putString("caption", caption); 
parameters.putString("name", name); 
parameters.putString("message", msg); 

try { 
    String response = mFacebook.request("me/feed", parameters, "POST"); 
} catch (IOException e) { 
    Log.e("Error", e.toString()); 
} 

我得到很多的警告,但看過這是正常的(也是,我得到的「消息」,但仍然會將一條警告:

Key caption expected byte[] but value was a java.lang.String. The default value <null> was returned. 
Attempt to cast generated internal exception: 
java.lang.ClassCastException: java.lang.String 
+0

也行,我使用的是當前FB SDK(上週下載) – Matt

+0

你得到任何錯誤? byteArray的任何衝突,String類拋出異常? – sat

+0

@sat,是ClassCastException,該方法仍然發佈到FB牆,但沒有額外的參數,如標題,Limk,名稱等 – Matt

回答

7

檢查我的編輯答案,它會發布用戶的牆:

它會顯示異常的情況下,但不要理會它,您的文章將被成功

public void postOnWall() { 
    try{ 
     Bundle parameters = new Bundle(); 
     parameters.putString("message", "Text is lame. Listen up:"); 
     parameters.putString("name", "Name"); 
     parameters.putString("link", "http://www.google.com"); 
     parameters.putString("caption", "Caption"); 
     parameters.putString("description", "Description"); 

     String response = facebook.request("me/feed",parameters,"POST"); 
     Log.v("response", response); 
    } 
    catch(Exception e){} 
} 
+0

這不起作用,要麼允許我發佈鏈接,標題等到流 – Matt

+0

@Matt一個問題,你需要發佈有或沒有對話?? – Venky

+0

沒有對話框(請不要告訴我你不能發佈額外的參數):) – Matt

0

請參閱下面的代碼。它正在運行代碼。嘗試一次。

public void postOnWall(String msg) { 
    Log.d("Tests", "Testing graph API wall post"); 
    try { 
     String response = facebook.request("me"); 
     Bundle parameters = new Bundle(); 
     parameters.putString("message", msg); 
     parameters.putString("description", "test test test"); 
     response = facebook.request("me/feed", parameters, 
       "POST"); 
     Log.d("Tests", "got response: " + response); 
     if (response == null || response.equals("") || 
       response.equals("false")) { 
      Log.v("Error", "Blank response"); 
     } 
    } 
    catch(Exception e) { 
     e.printStackTrace(); 
    } 
} 
+0

這正是我建立的代碼。它仍然只發送消息,而不是描述 – Matt

+0

在facebook牆消息發佈的情況下,消息和說明沒有區別。信息本身是對留言信息的描述(不是圖像信息)。 – Debarati

+0

好吧,這很有道理,但爲什麼Link,Name,Caption不起作用? – Matt

0

試試這個它會與身份驗證對話框

 private static final String[] PERMISSIONS = 
      new String[] {"publish_stream", "read_stream", "offline_access"}; 


    Facebook authenticatedFacebook = new Facebook(APP_ID); 


    postButton.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      authenticatedFacebook.authorize(Tests.this, PERMISSIONS, 
        new TestPostListener()); 
     } 
    }); 


public class TestPostListener implements DialogListener { 

    public void onComplete(Bundle values) { 
     try { 
      Log.d("Tests", "Testing request for 'me'"); 
      String response = authenticatedFacebook.request("me"); 
      JSONObject obj = Util.parseJson(response); 

      Log.d("Tests", "Testing graph API wall post"); 
      Bundle parameters = new Bundle(); 
      parameters.putString("message", "Amit Siddhpura"); 
      parameters.putString("description", "Hi Mr. Amit Siddhpura"); 
      response = authenticatedFacebook.request("me/feed", parameters, 
        "POST"); 
      Log.d("Tests", "got response: " + response); 
     } catch (Throwable e) { 
      e.printStackTrace(); 
     } 
    } 

    public void onCancel() { 
    } 

    public void onError(DialogError e) { 
     e.printStackTrace(); 
    } 

    public void onFacebookError(FacebookError e) { 
     e.printStackTrace(); 
    } 
}