gpt4 book ai didi

php - 如何在 PHP SDK 中使用访问 token 并使用 fql 检索 user_activities 参数?

转载 作者:行者123 更新时间:2023-12-04 05:54:54 24 4
gpt4 key购买 nike

我想知道如何在 PHP SDK 中使用 getAccessToken() 获取的访问 token
以下是我尝试显示用户电子邮件 ID 以及用户事件的代码片段:
当我运行此代码时,电子邮件和用户事件为空白,我该如何解决?

      <?php



require '/home/vespanve/public_html/facebook-php-sdk/src/facebook.php';

$facebook = new Facebook(array(
'appId' => '39653698mmmmm448',
'secret' => 'd7681299469mmmmmmmmmmmmm',
));

$config = array(
'appId' => '39653698mmmmm448',
'secret' => 'd7681299469mmmmmmmmmmmmm',
);

$facebook = new Facebook($config);
$user_id = $facebook->getUser();
$access_token = $facebook->getAccessToken();
$facebook->setAccessToken($access_token);

?>
<html>
<head></head>
<body>

<?
if($user_id) {

// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {

$fql = 'SELECT name from user where uid = ' . $user_id;
$fqlmail = 'SELECT email from user where uid = ' . $user_id;
$fqlact = 'SELECT user_activities from user where uid = ' . $user_id;
$ret_obj = $facebook->api(array(
'method' => 'fql.query',
'query' => $fql,
));
$ret_obj2 = $facebook->api(array(
'method' => 'fql.query',
'access_token' => $cookie['access_token'],
'query' => $fqlmail,
));
$ret_obj3 = $facebook->api(array(
'method' => 'fql.query',
'access_token' => $cookie['access_token'],
'query' => $fqlact,
));

// FQL queries return the results in an array, so we have
// to get the user's name from the first element in the array.
echo '<pre>Name: ' . $ret_obj[0]['name'] . '</pre>';
echo '<pre>Email: ' . $ret_obj2[0]['email'] . '</pre>';
echo '<pre>Activities: ' . $ret_obj3[0]['user_activities'] . '</pre>';
$facebook->destroySession();



} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '">login.</a>';
error_log($e->getType());
error_log($e->getMessage());
}
} else {

// No user, so print a link for the user to login
$login_url = $facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '">login.</a>';

}
?>

</body>
</html>

最佳答案

您需要请求扩展权限:

$params = array(
'scope' => 'email, user_activities',
'redirect_uri' => 'https://www.myapp.com/post_login_page'
);

$loginUrl = $facebook->getLoginUrl($params);

有关这方面的更多信息,您可以在这里查看:

http://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/

对于这里的权限:

http://developers.facebook.com/docs/reference/api/permissions/

关于php - 如何在 PHP SDK 中使用访问 token 并使用 fql 检索 user_activities 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9631352/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com