CURL / Facebook graph api help

Discussion in 'Programming' started by frobak, Jul 17, 2011.

  1. #1
    Hi

    Im trying to post to the graph api using curl. This script already obtains access tokens etc.

    I've managed to post a feed item using this, so this works fine


    	if($_POST['txt']){
    		//if there is a posted data, then post it in facebook
    		$params = array('access_token'=>$_SESSION['accesstoken'], 'message'=>$_POST['txt'] );
    		$url = 'https://graph.facebook.com/255500227799817/feed';
    
    		$ch = curl_init();
    		curl_setopt_array($ch, array(
    		CURLOPT_URL => $url,
    		CURLOPT_POSTFIELDS => $params,
    		CURLOPT_RETURNTRANSFER => true,
    		CURLOPT_SSL_VERIFYPEER => false,
    		CURLOPT_VERBOSE => true
    		));
    		$result = curl_exec($ch);
    		curl_close($ch);
    
    	}
    PHP:

    But i cant post a comment on the feed item using this, but surely it should work the same? The documentation says so?

    	if($_POST['new-comment']){
    	
    		$fb_post_id = $_POST['new-fb-post-id'];
    		$fb_new_comment = $_POST['new-comment'];
    		
    		//if there is a posted data, then post it in facebook
    		$params = array('access_token'=>$_SESSION['accesstoken'], 'message'=>$_POST['new_comment']);
    		$url = 'https://graph.facebook.com/'.$fb_post_id.'/comments';
    
    		$ch = curl_init();
    		curl_setopt_array($ch, array(
    		CURLOPT_URL => $url,
    		CURLOPT_POSTFIELDS => $params,
    		CURLOPT_RETURNTRANSFER => true,
    		CURLOPT_SSL_VERIFYPEER => false,
    		CURLOPT_VERBOSE => true
    		));
    		$result = curl_exec($ch);
    		curl_close($ch);
    
    	}
    PHP:

    Any thoughts?

    cheers
     
    frobak, Jul 17, 2011 IP
  2. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #2
    What does $result return when viewed? Is it giving you any error messages?
     
    exodus, Jul 21, 2011 IP