2012-05-17 22 views
0

我舉了一個小例子,通過Android應用向Facebook供稿發佈消息。 它工作的很好,但我只是想添加更多的內容,像Facebook頁面的圖標,鏈接和更多的東西..將內容添加到來自Android應用的Facebook供稿

我怎樣才能將這些參數添加到我的Facebook對話框以發佈它們呢?

public class MainActivity extends Activity 
{ 

    Facebook facebook = new Facebook("Here i got my app id."); 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     // Posting my message, maybe here i could add paramterers like icon and a link etc..? 
     facebook.dialog(MainActivity.this, "feed", new PostDialogListener()); 
    } 

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) 
    { 

    super.onActivityResult(requestCode, resultCode, data); 
    facebook.authorizeCallback(requestCode, resultCode, data); 

    } 

public abstract class BaseDialogListener implements DialogListener { 
     @Override 
     public void onFacebookError(FacebookError e) { 


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


    } 

    public class PostDialogListener extends BaseDialogListener { 
     @Override 
     public void onComplete(Bundle values) { 
      final String postId = values.getString("post_id"); 
      if (postId != null) { 
       ki("Message posted on the wall."); 
      } else { 
       ki("No message posted on the wall."); 
      } 
      } 
     } 
     } 

回答

1
private void publishPhoto(String imageURL) { 
    Log.d("FACEBOOK", "Post to Facebook!"); 

    try { 

     JSONObject attachment = new JSONObject(); 
     attachment.put("message", Utils.s(R.string.fb_message)); 
     attachment.put("name", Utils.s(R.string.fb_name)); 
     attachment.put("href", Utils.s(R.string.url_dotzmag)); 
     attachment.put("description", Utils.s(R.string.fb_description)); 

     JSONObject media = new JSONObject(); 
     media.put("type", "image"); 
     media.put("src", imageURL); 
     media.put("href", Utils.s(R.string.url_dotzmag)); 
     attachment.put("media", new JSONArray().put(media)); 

     JSONObject properties = new JSONObject(); 

     JSONObject prop1 = new JSONObject(); 
     prop1.put("text", "Dotz App on Android Market"); 
     prop1.put("href", Utils.s(R.string.url_android_market)); 
     properties.put("Get the App for free", prop1); 

     JSONObject prop2 = new JSONObject(); 
     prop2.put("text", "Dotz Tuning on Facebook"); 
     prop2.put("href", Utils.s(R.string.url_facebook_fanpage)); 
     properties.put("Visit our fanpage", prop2); 

     attachment.put("properties", properties); 

     Log.d("FACEBOOK", attachment.toString()); 

     Bundle params = new Bundle(); 
     params.putString("attachment", attachment.toString()); 
     mFacebook.dialog(mActivity, "stream.publish", params, new PostPhotoDialogListener()); 
     //mAsyncRunner.request("me/feed", params, "POST", new WallPostRequestListener(), null); 

    } catch (JSONException e) { 
     Log.e("FACEBOOK", e.getLocalizedMessage(), e); 
    } 
} 
public class PostPhotoDialogListener extends BaseDialogListener { 

    public void onComplete(Bundle values) { 
     final String postId = values.getString("post_id"); 
     if (postId != null) { 
      Log.d("FACEBOOK", "Dialog Success! post_id=" + postId); 
      Toast.makeText(mActivity, "Successfully shared on Facebook!", Toast.LENGTH_LONG).show(); 
      /* 
      mAsyncRunner.request(postId, new WallPostRequestListener()); 
      mDeleteButton.setOnClickListener(new OnClickListener() { 
       public void onClick(View v) { 
        mAsyncRunner.request(postId, new Bundle(), "DELETE", 
          new WallPostDeleteListener(), null); 
       } 
      }); 
      */ 
     } else { 
      Log.d("FACEBOOK", "No wall post made"); 
     } 
    } 
} 
+0

PostPhotoDialogListener不能被解析爲一個類型, 我怎麼能實現它,請幫我 –

+0

你想用對話或不對話 – Venky

+0

後得到了現在的感謝。 –