我有:
$user = json_decode(file_get_contents(
'https://graph.facebook.com/me?access_token=' .
$cookie['access_token']), true);
var_dump($user);
工作正常并提供配置文件输出。
可是:
$events = json_decode(file_get_contents(
'https://graph.facebook.com/me/events?access_token=' .
$cookie['access_token']), true);
var_dump($events);
给出:
object(stdClass)#5 (1) { ["data"]=> array(0) { } }
我不确定这是一个空对象,还是我没有正确访问'数据'里面的内容。但是,我知道事实上有与我的个人资料相关的事件。权限已被授予,所以这不是问题。任何人都知道如何返回我的个人资料的所有事件名称?
答案 0 :(得分:0)
为了在PHP中获取事件,您必须按照以下步骤进行操作
请求正确的访问令牌,请点击此链接 facebook: permanent Page Access Token?
将您的访问令牌替换为发送短信的YOUR_ACCESS_TOKEN字段
<?php
$json_string = 'https://graph.facebook.com/5973249561/events/?access_token=YOUR_ACCESS_TOKEN&fields=id,name,description,start_time,place,cover,end_time&limit=999';
$obj = json_decode(curl_get_contents($json_string),true);
foreach ($obj['data'] as $key => $value) {
echo @$value['id'];
echo @$value['name'];
echo @$value['start_time'];
echo @$value['place'];
echo @$value['cover']['source'];
}
function curl_get_contents($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
?>