facebook图形API不返回事件
问题描述:
我正在尝试使用图形API调用来返回登录到我的应用程序的用户的事件。然而,$ event始终为空,虽然我自己创建了一堆事件,任何人都可以帮忙吗?facebook图形API不返回事件
这里是我的代码登录到事件API调用:
require_once('AppInfo.php');
// Enforce https on production
if (substr(AppInfo::getUrl(), 0, 8) != 'https://' && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
header('Location: https://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
}
// This provides access to helper functions defined in 'utils.php'
require_once('utils.php');
require_once('sdk/src/facebook.php');
$facebook = new Facebook(array(
'appId' => AppInfo::appID(),
'secret' => AppInfo::appSecret(),
'sharedSession' => true,
'trustForwarded' => true,
));
$user_id = $facebook->getUser();
if ($user_id) {
try {
// Fetch the viewer's basic information
$basic = $facebook->api('/me');
} catch (FacebookApiException $e) {
// If the call fails we check if we still have a user. The user will be
// cleared if the error is because of an invalid accesstoken
if (!$facebook->getUser()) {
header('Location: '. AppInfo::getUrl($_SERVER['REQUEST_URI']));
exit();
}
}
// This fetches some things that you like . 'limit=*" only returns * values.
// To see the format of the data you are retrieving, use the "Graph API
// Explorer" which is at https://developers.facebook.com/tools/explorer/
$likes = idx($facebook->api('/me/likes?limit=4'), 'data', array());
// This fetches 4 of your friends.
$friends = idx($facebook->api('/me/friends?limit=4'), 'data', array());
// And this returns 16 of your photos.
$photos = idx($facebook->api('/me/photos?limit=16'), 'data', array());
// Fetch the event information
// $events = idx($facebook->api('/me/events?limit=5'), 'data', array());
$events = $facebook->api('/me/events','GET');
print("11111");
if($events == null) print("empty");
答
我认为没有登录代码在你的榜样,你一定要在用户登录?见PHP SDK“用法”:https://github.com/facebook/facebook-php-sdk
无论如何,我只是想这在我的项目之一,我得到同样的呼叫的用户事件,但我需要的权限“user_events”:
$facebook->getLoginUrl(array('scope' => 'user_events'));
感谢帮助!我实际上使用了不同的方式登录使用JavaScript和登录按钮的帮助。我们在我们的范围内添加了“user_events”作为
,然后它的工作! – 2013-05-02 22:12:25啊,javascript总是更好的登录(可用性和东西),这是完美的。很高兴我能帮上忙 :) – luschn 2013-05-02 22:54:04