[英]How to receive the facebook graph api returned data?
I am new to stackoverflow and programming. 我是stackoverflow和编程的新手。 I am just learing php and decided to work with facebook place search api for just practice purpose. 我只是学习php,并决定出于实际目的使用Facebook位置搜索api。
I have written the below code in php: 我已经在php中编写了以下代码:
$FacebookGraphURL = 'https://graph.facebook.com/search?q='.$keyword.'&type=place' . htmlentities('¢er=') .$center.'&distance='.$distance.'&access_token='.ACCESS_TOKEN;
$FacebookGraphJSON = @file_get_contents($FacebookGraphURL);
$dataArray = json_decode($FacebookGraphJSON);
But it don't return anything. 但是它什么也不会返回。 I think this is not appropriate way to get from graph api.I have searched quite a lot but could not find one which I can understand as I am a novice. 我认为这不是从图api获取的合适方法。我已经搜索了很多,但是由于我是新手所以找不到我可以理解的方法。
Can any one help me. 谁能帮我。
1) htmlentities('¢er=') .$center
should be ¢er=' . htmlentities($center) .
1) htmlentities('¢er=') .$center
应该是¢er=' . htmlentities($center) .
¢er=' . htmlentities($center) .
2) don't use the @ before file_get_contents
this will suppress error (warning in this case) when your file request fails. 2)不要在file_get_contents
之前使用@,这样file_get_contents
文件请求失败时出现错误(在这种情况下为警告)。
try the code below: 试试下面的代码:
error_reporting(E_ALL);
ini_set('display_errors', 'On');
define('ACCESS_TOKEN','**********************************************');
$keyword = 'coffee';
$center= urlencode('37.76,-122.427');
$distance=1000;
$FacebookGraphURL = 'https://graph.facebook.com/search?q='.$keyword.'&type=place¢er='.$center.'&distance='.$distance.'&access_token='.ACCESS_TOKEN;
$FacebookGraphJSON = file_get_contents($FacebookGraphURL);
$dataArray = json_decode($FacebookGraphJSON);
var_dump($dataArray);
exit;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.