Jump to content

Posting a comment on the news feed [facebook api]


stealthrt

Recommended Posts

Hey all i am using the following code to post to a posting on my news feed:

    <?php
    require '../src/facebook.php';
    
    $facebook = new Facebook(array(
      'appId'  => 'xxxxxxxxxxxxxxx',
      'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
      'fileUpload' => true,
      'cookie' => true
    ));
    
    $user = $facebook->getUser();
    
    if ($user) {
      try {
     $access_token  = $facebook->getAccessToken();
        $user_profile  = $facebook->api('/me');
     $comment = $facebook->api('/xxxxxxxxxxxxxx/comments', 
      'POST', 
     array(
       'access_token' => $access_token,
       'message' => 'testing!'
     )
     );
      } catch (FacebookApiException $e) {
        echo ($e);
        $user = null;
      }
    }
 
    <?php if ($user): ?>
     <a href="<?php echo $logoutUrl; ?>">Logout</a>
    <?php else: ?>
     <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
    <?php endif ?>
    
    if ($user) {
      $logoutUrl = $facebook->getLogoutUrl();
    } else {
      $statusUrl = $facebook->getLoginStatusUrl();
       $params = array(
       'scope' => 'read_stream, friends_likes, email, read_mailbox, read_requests, user_online_presence, friends_online_presence, manage_notifications, publish_actions, publish_stream, user_likes, user_photos, user_status, user_videos, read_insights'
     );
      $loginUrl = $facebook->getLoginUrl($params);
    }
    
    ?>
 
    <?php print_r($user_profile); ?>
For some reason i get this error:
 
OAuthException: (#221) Photo not visible
 
And i have no idea since i am posting a text comment and not even an image??
 
If i comment out the code line

/*$comment = $facebook->api('/xxxxxxxxxxxxxx/comments', 
      'POST', 
     array(
       'access_token' => $access_token,
       'message' => 'testing!'
     )
     );*/
it works just fine (as in, displays my info with user_profile). I've tried reading over the page that tells you how to use the comments https://developers.facebook.com/docs/graph-api/reference/object/comments/ and i do - it just doesn't seem to want to work?
 
Using the graph API i was able to do the same thing i am trying to do via PHP so i know it works since it returns a json ID and when i refresh the page i see the "testing" comment...:
RQfNv.png
 
And what makes it more odd is that, i can use the above code to comment on just a comment that doesnt have an image posted... But if i am commenting on a image that was posted then i get that error???!?!?!?
 
I use this code to sussesfully post to a non-image post (as in, just someone posting text). Where xxxxxxxxxxxx is the post ID and yyyyyyyyyyyyyy is the users ID who posted the comment that i am posting my comment to.

$comment = $facebook->api('/xxxxxxxxxxx_yyyyyyyyyyyyy/comments', 
'post', 
array(
 'message' => 'testing!',
)
);

 
What am i missing???
Edited by stealthrt
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.