2012-09-16 120 views
0

我正在使用Facebook SDK,我想發佈消息在我的牆上。這是近兩天,我耕耘互聯網,但我沒有成功找到我的問題。讓我說我做了什麼。Android,發佈在我的Facebook上的牆上的消息

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     Log.i(TAG, "Try to create activity..."); 

     // Close activity if app id is not specified. 
     if (FACEBOOK_APPID == null || FACEBOOK_APPID == "") { 
      Log.e(TAG, "Facebook Applicaton ID must be specified before running this screen."); 
      closeActivity(); 
     } 

     // Getting extra info which is passed by caller activity. 
     // If we are here by mistake(Caller didn't send required parameter) close activity. 
     Bundle extras = getIntent().getExtras(); 
     if(extras == null) { 
      Log.i(TAG, "No data passed to this activity. Activity closed."); 
      closeActivity(); 
     } 
     // Get Message 
     message = extras.getString("FB_WALLPOST"); 
//  Log.i(TAG, "message>>> " + message); 


     mFacebook = new Facebook(FACEBOOK_APPID); 
     mAsyncRunner = new AsyncFacebookRunner(mFacebook); 

     SessionStore.restore(mFacebook, this); 
     SessionEvents.addAuthListener(new SampleAuthListener()); 
     SessionEvents.addLogoutListener(new SampleLogoutListener()); 

//  mFacebook.dialog(FacebookActivity.this, "feed", params, new SampleDialogListener()); 

     Thread thread = new BasicThread(); 
     thread.start(); 

    } 

根據我的研究,我發現Facebook.dialog不能使用。這就是它評論說的原因。 另外我發現我們需要使用Facebook.request而不是那個。我在SDK中發現了Note that this method blocks waiting for a network response, so do not call it in a UI thread.。因此,我創建了另一個線程來處理髮布過程。

當線程啓動後面的方法會被調用。

public class BasicThread extends Thread { 
    public void run() { 
     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 = mFacebook.request("me/feed",parameters,"POST"); 
      Log.v("response", response); 
     } 
     catch(Exception e){} 
    } 
} 

那些建議此代碼的人被告知該方法對他們工作正常。但是,我不知道爲什麼它不適合我。在logcat的

響應:

09-16 17:06:21.860: D/Facebook-Util(26652): POST URL: https://graph.facebook.com/me/feed 
09-16 17:06:23.350: V/response(26652): {"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}} 

任何建議,將不勝感激。謝謝

回答

0

沒有訪問令牌正在發送,但是,它? 嘗試類似:

String token = getAccessToken(); 

if (token){ 
    parameters.putString("access_token", token); 
    String response = mFacebook.request("me/feed",parameters,"POST"); 
} else { 
    // Log the user in 
} 
相關問題