Simke Nys
Simke Nys

Reputation: 72

PHP Facebook graph API search cURL - no results

I've got a problem with the facebook graph API. I'm trying to do a search through the posts on facebook filtered on a keyword, but I can't seem to fetch the results. When I copy my url in a browser, it works fine.

I think it has something to do with my cURL parameters, i'm pretty new to this.

<?php
$keyword = $_POST['keyword'];
$graph_url = "https://graph.facebook.com/search?&type=post&locale=en_US&q=".$keyword;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $graph_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);

print $result;
?>

Anyone knows what's wrong with this, or anyone who knows a different solution to fetch search results from facebook.

Upvotes: 0

Views: 4204

Answers (1)

Scorpil
Scorpil

Reputation: 1526

As you are trying to reach site through HTTPS, you should turn off SSL verification, or add certificate to verify with. Details here: http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/

Quick fix:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

Or you can just change your url to:

http://graph.facebook.com/search?&type=post&locale=en_US&q=

Upvotes: 3

Related Questions