我正在尝试从 facebook 获取所有公共(public)事件,
当我尝试从我的服务器执行我的 php 代码时,出现错误:Uncaught OAuthException: (#200) Must have a valid access_token to access this endpoint throw in/....../sdk/src/base_facebook.php 第 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 中的相同.....
util.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");
}
最佳答案
可能与此有关
关于php - Facebook : OAuthException: (#200) Must have a valid access_token to access this endpoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16014649/