在Android的任何Facebook墙上发表评论

时间:2011-12-16 12:28:50

标签: android facebook

我使用Facebook sdk(https://github.com/facebook/facebook-android-sdk/)来显示NewsFeed。我可以在我的应用程序中显示所有新闻源墙。

现在我需要在任何可见的墙上发送评论。我如何通过我的应用程序成为墙和评论。任何人都可以帮助我吗?

提前致谢。

3 个答案:

答案 0 :(得分:7)

要明确:

  • 您只能在帖子评论(而不是实际的墙本身)
  • 您只能喜欢 评论发布(而不是真正的墙本身)

使用Facebook SDK,您可以执行以下操作以获得评论:

Facebook facebook = new Facebook(APP_ID);
String commentText = "I love blu-ray";
String postId = "7568536355_333422146668093"; //a lifehacker post about blu-ray

String graphPath = postId + "/comments";
Bundle params = new Bundle();
params.putString("message", commentText);
facebook.request(graphPath, params, "POST");

...以及以下内容:

Facebook facebook = new Facebook(APP_ID);
String postId = "7568536355_333422146668093"; //a lifehacker post about blu-ray

String graphPath = postId + "/likes";
facebook.request(graphPath, new Bundle(), "POST");

答案 1 :(得分:0)

您应该熟悉Facebook Android SDK usage of Graph APIPost object(评论连接)和Comment Object图谱API文档(喜欢部分)。

  • 您不能对墙壁本身发表评论,而是在其中一个帖子上发表评论。
  • 您可以通过图谱API
  • 在墙上发布
  • 您可以通过图谱API
  • 发表评论
  • 您可以通过图谱API
  • 为帖子和评论创建相似内容

<强>更新

下面有关创建评论和喜欢它的示例(如何为帖子创建评论的示例以及已经在此问题的其他答案中显示的帖子):

// I assume you already have post_id (which is constructed from USERID_MESSAGEID)
Facebook mFacebook = new Facebook(APP_ID);
Bundle params = new Bundle();
params.putString("message", "This is a comment text");
String comment_id = facebook.request(post_id + "/comments", params, "POST");

// Once you have comment_id it can be used for liking it.
facebook.request(comment_id + "/likes", new Bundle(), "POST");

答案 2 :(得分:-1)

 'Use Facebook Api as library download api and use it as library'







    private static final String FACEBOOK_APPID = "Your Api key";

                Facebook facebook = new Facebook(FACEBOOK_APPID);

      facebook.authorize(this,new String[] { "user_photos,publish_checkins,publish_actions,publish_stream" },
                             new DialogListener() {
                                @Override
                                public void onComplete(Bundle values) {
                                    postImageonWall();
                                    try {
                                        facebook.logout(TestActivity.this);

                                    } catch (MalformedURLException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
                                    // finish();

                                }

                                @Override
                                public void onFacebookError(FacebookError error) {

                                }

                                @Override
                                public void onError(DialogError e) {

                                }

                                @Override
                                public void onCancel() {

                                }

使用postImageOnWall方法

            public void postImageonWall() {

                    byte[] data = null;

                    Bitmap bi = BitmapFactory.decodeFile(filepath);
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
                    data = baos.toByteArray();
                AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
                    mAsyncRunner.request(null, params, "POST", new RequestListener() {

                        @Override
                        public void onMalformedURLException(MalformedURLException e,
                                Object state) {
                            Log.d("MalformedURLException", e.getMessage());
                        }

                        @Override
                        public void onIOException(IOException e, Object state) {
                            Log.d("onIOException", e.getMessage());
                        }

                        @Override
                        public void onFileNotFoundException(FileNotFoundException e,
                                Object state) {
                            Log.d("FileNotFoundException", e.getMessage());
                        }

                        @Override
                        public void onFacebookError(FacebookError e, Object state) {
                            Log.d("onFacebookError", e.getMessage());
                        }

                        @Override
                        public void onComplete(String response, Object state) {
                            Log.d("onComplete", response);
                        }
                    }, null);

                }
相关问题