简体   繁体   中英

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.

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=

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM