2012-11-03 46 views
0

我想使用facebook SDK提交一個簡單的發佈請求。 下面的代碼:通過Android應用程序在Facebook中創建一個簡單的帖子

public void ShareLinkOnFacebook() 
    { 
     Facebook mFacebook = ((GlobalVars)getApplicationContext()).facebook; 
     AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(mFacebook); 
     Bundle params = new Bundle(); 
     params.putString("message", place.name); 
     params.putString("link", "http://www.facebook.com"); 
     mAsyncFbRunner.request("me/feed", params, "POST", new RequestListener()); 
    } 

,但我有編譯錯誤說RequestListener不能被解析爲一個類型。爲了使其工作我需要做些什麼?

+0

你創建RequestListener監聽? –

+0

@ChiragRaval不,我沒有,我真的不知道該怎麼做。 – idish

+0

此鏈接推薦最佳的API爲Facebook: http://stackoverflow.com/questions/5076691/integrating-facebook-twitter-social-networks-in-android – user1722283

回答

0

請檢查此監聽器。

public void postOnWall(String msg) { 
     Log.d("Tests", "Testing graph API wall post"); 
     try { 
       String response = mFacebook.request("me"); 
       Bundle parameters = new Bundle(); 
       parameters.putString("message", msg); 
       parameters.putString("description", "test test test"); 
       response = mFacebook.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

它說,BaseRequestListener不能被解析爲一個類型。 – idish

+0

@idish檢查我的更新答案。 –

0

試試這個它我的工作代碼: - 上wallpost按鈕點擊: -

mPostButton.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      mFacebook.dialog(Class.this, "feed", 
        new SampleDialogListener()); 
     } 

&

 public class SampleDialogListener extends BaseDialogListener { 

    public void onComplete(Bundle values) { 
     final String postId = values.getString("post_id"); 
     if (postId != null) { 
      Log.d("Facebook-Example", "Dialog Success! post_id=" + postId); 
      mAsyncRunner.request(postId, new WallPostRequestListener()); 

      mDeleteButton.setVisibility(View.VISIBLE); 
     } else { 
      Log.d("Facebook-Example", "No wall post made"); 
     } 
    } 
} 

& BaseDialogListner:---

public abstract class BaseDialogListener implements DialogListener { 

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

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

public void onCancel() { 
} 

}

public class WallPostRequestListener extends BaseRequestListener { 

    public void onComplete(final String response, final Object state) { 
     Log.d("Facebook-Example", "Got response: " + response); 
     String message = "<empty>"; 
     try { 
      JSONObject json = Util.parseJson(response); 
      message = json.getString("message"); 
     } catch (JSONException e) { 
      Log.w("Facebook-Example", "JSON Error in response"); 
     } catch (FacebookError e) { 
      Log.w("Facebook-Example", "Facebook Error: " + e.getMessage()); 
     } 
     final String text = "Your Wall Post: " + message; 
     VideoUpload.this.runOnUiThread(new Runnable() { 
      public void run() { 
       mText.setText(text); 
      } 
     }); 
    } 
} 

& BaseRequestListner: -

public abstract class BaseRequestListener implements RequestListener { 

public void onFacebookError(FacebookError e, final Object state) { 
    Log.e("Facebook", e.getMessage()); 
    e.printStackTrace(); 
} 

public void onFileNotFoundException(FileNotFoundException e, 
     final Object state) { 
    Log.e("Facebook", e.getMessage()); 
    e.printStackTrace(); 
} 

public void onIOException(IOException e, final Object state) { 
    Log.e("Facebook", e.getMessage()); 
    e.printStackTrace(); 
} 

public void onMalformedURLException(MalformedURLException e, 
     final Object state) { 
    Log.e("Facebook", e.getMessage()); 
    e.printStackTrace(); 
} 
+0

謝謝你的回答,我試圖通過一些代碼更改來實現它以適應我的需求,並且它不起作用(我沒有得到任何例外)。你在代碼中看到問題了嗎? http://pastebin.com/pguxr1qa – idish

+0

也許如果你能給我這個請求本身,它會幫助我解決問題。 – idish

+0

我已經添加了對我有用的整個代碼。嘗試這個。 –

相關問題