views:

960

answers:

5

In PHP, I am trying to post a status to our Facebook fan page using the graph api, despite following the intructions facebook give, the following code does not seem to update the status.

Here is the code;

$xPost['access_token'] = "{key}";
$xPost['message'] = "Posting a message test.";

$ch = curl_init('https://graph.facebook.com/{page_id}/feed'); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $xPost); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); 
curl_setopt($ch, CURLOPT_CAINFO, NULL); 
curl_setopt($ch, CURLOPT_CAPATH, NULL); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 

$result = curl_exec($ch); 

Does anyone know why this code is not working? The access_token is correct.

A: 

it seems "CURLOPT_SSL_VERIFYPEER" should be set to 0;

e.g. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
Simon R
A: 

I also have the same problem, I used this option also

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

But still no luck.. Can anybody help please

Subeesh

Subeesh
+1  A: 
    $url = "https://graph.facebook.com/ID_HERE/feed";
    $ch = curl_init();
    $attachment =  array(   'access_token'  => 'your token',                        
                        'name'          => "Title",
                        'link'          => "www.google.com",
                        'description'   => 'description here',
                    );

    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
    $result= curl_exec($ch);

    curl_close ($ch);
Soufiane Hassou
just another quick question. above command returns some value such as "{"id":"1347466624_1603672123512"}". Is there any way to disable this output?
ebae
A: 

HI,

THANKS VERY MUCH FOR THIS POST, It was very special to me because, i was able to use this point to get posts written to facebook using CURL.

Thank you once again. Hope that in future, I will also be able to contribute to people via this.

Thanks and Regards,

Saravanan.

A: 

Can i post status without using curl?

Tola