【问题标题】:Adding content to facebook feed from Android app从 Android 应用程序向 Facebook 提要添加内容
【发布时间】:2012-05-17 19:43:38
【问题描述】:

我做了一个小例子,通过 Android 应用向 Facebook 提要发布消息。 效果很好,但我只想在帖子中添加更多内容,例如 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.");
            }
            }
        }
      }

【问题讨论】:

    标签: android facebook


    【解决方案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");
            }
        }
    }
    

    【讨论】:

    • PostPhotoDialogListener 无法解析为类型,我该如何实现它请帮助我
    • 您想使用 Dialog 或不使用 Dialog 发帖
    猜你喜欢
    • 1970-01-01
    • 2011-04-13
    • 2013-09-04
    • 2023-03-09
    • 2012-10-21
    • 2021-10-18
    • 1970-01-01
    • 1970-01-01
    • 2017-03-01
    相关资源
    最近更新 更多