Upload comments to particular post of facebook with object_id android
Asked Answered
M

2

0

Hello friends I want to post comment to particular post in facebook with my android app, below is my code-

I Fetch All comments from URL which is below

http://retirementhomeslisting.com/home-detail/canterbury-place-83

Bundle mBundle=new Bundle();
mBundle.putString("message","testing...1234555"); 
@SuppressWarnings("deprecation")
Facebook fb=new Facebook(getResources().getString(R.string.fb_app_id));
try {
    fb.request("478409145610921/comments",mBundle,"POST");
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Here I provide one link which you can see all comment list with respective above object_id

Link for comment list for 478409145610921 object_id

When i run above code comment is not post with respective object_id so Any idea how can i solve it? EDIT Answer

Bundle mBundle=new Bundle();
                        mBundle.putString("message","testing...1234555"); 
                        @SuppressWarnings("deprecation")
                        Facebook fb=new Facebook(getResources().getString(R.string.fb_app_id));
                        try {
                        fb.request("1309634065_478409145610921/comments",mBundle,"POST");

                        } catch (FileNotFoundException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (MalformedURLException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
Malefaction answered 31/3, 2014 at 13:1 Comment(0)
A
3

To post a comment on a post, you need a post_id instead of object_id.

So your API call must be-

/{post_id}/comments

(post_id is also a field in the comments table)

Edit:

You must be using a comment plugin and trying to post a comment to that. Unfortunately, facebook don't allows you to do that! (Logical- since most of them are public, to avoid spamming, else anyone could flood comments to that post)

If you check the response here, you'll get:

{
  "error": {
     "message": "(#100) Comments may not be added to a comment plugin", 
     "type": "OAuthException", 
     "code": 100
  }
}

You can test these API call on Graph API Explorer also.

Adam answered 31/3, 2014 at 13:53 Comment(12)
Sahil Mittal : post_id in my case post_fbid which i get above json formate is it you say?Malefaction
No, change your query. Check this link. Your postid is 1309634065_478409145610921Adam
Sahil Mittal :I try your code but still not post comment in the post!! see my edit code pls.Malefaction
But what's the response this time?Adam
Sahil Mottal :: When i post comment just print link like 04-01 09:39:47.105: D/Facebook-Util(6675): POST URL: graph.facebook.com/1309634065_758983910781864/commentsMalefaction
Sahil Mittal :: no when i paste this url to browser it give message "Sorry, this page isn't available"Malefaction
My bad. You are fetching the comments from a url! You didn't mention that in a question! I'll checkAdam
Sahil Mittal : ohh ya brother !! i forgot it for mention i fetch all comments from url !! now see my edit line in aboveMalefaction
Sahil Mittal : So using url it is not possible right?Malefaction
No. Someone posted it as a bug earlier: developers.facebook.com/bugs/164794086987157. But it was closed saying: This functionality was never and is not intended to be available. So, this is not possible! Only the comments on the facebook are accessible via graph api. You can only fetch the comments from url.Adam
Sahil Mittal Ok bro.. Thnaks for your time and effort !! but thenafter i will accept your answer and +1 vote for thatMalefaction
Great! :) If you find some issue using the facebook APIs you may contact me in case your question not getting attention hereAdam
B
0

Using Graph API:

...
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]) {
    [[[FBSDKGraphRequest alloc]
      initWithGraphPath:@"post_id/likes"
      parameters: @{ @"like" : @"true"}
      HTTPMethod:@"POST"]
      startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
         if (!error) {
             NSLog(@"It was liked.");
         }
     }];
}
...
Bryantbryanty answered 22/4, 2015 at 23:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.