简体   繁体   English

如何接收Facebook图形API返回的数据?

[英]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('&center=') .$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('&center=') .$center should be &center=' . htmlentities($center) . 1) htmlentities('&center=') .$center应该是&center=' . htmlentities($center) . &center=' . 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&center='.$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.

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