我正在尝试从 facebook 获取所有公共事件,
当我尝试从我的服务器执行我的 php 代码时,我收到错误:Uncaught OAuthException: (#200) Must have a valid access_token to access this endpoint throw in /....../sdk/src/base_facebook.php on第 1254 行
而如果我在heroku上执行相同的代码......它可以工作......我想在我的服务器上执行代码......请帮助......我的代码是......:
<?php
require_once('utils.php');
require_once('sdk/src/facebook.php');
$facebook = new Facebook(array(
'appId' => '.........',
'secret' => '..............',
'sharedSession' => true,
'trustForwarded' => true,
));
$events =idx($facebook->api('/search?q=trade&type=event&limit=5000&access_token=ksdkslhosihgksjdhlshfshdfgskdjhsklfhsklfhskfjhsdlkhslhslh'), 'data', array());
$var=1;
foreach($events as $event)
{
$id = idx($event, 'id');
$name = idx($event, 'name');
$owner = idx($event, 'owner');
$start_time = idx($event, 'start_time');
$end_time = idx($event, 'end_time');
$location = idx($event, 'location');
$description = idx($event, 'description');
echo "S.No:".$var."<br>";
echo "ID:".he($id)."<br>";
echo "Name:".he($name)."<br>";
echo "Owner:".he($owner)."<br>";
echo "start_time:".he($start_time)."<br>";
echo "end_time:".he($end_time)."<br>";
echo "location:".he($location)."<br>";
echo "description:".he($description)."<br>";
$var=$var+1;
}
?>
使用的 util.php 文件与 heroku 中的相同.....
实用程序.php
<?php
/**
* @return the value at $index in $array or $default if $index is not set.
*/
function idx(array $array, $key, $default = null) {
return array_key_exists($key, $array) ? $array[$key] : $default;
}
function he($str) {
return htmlentities($str, ENT_QUOTES, "UTF-8");
}