facebook-> getUser()返回0 [英] facebook->getUser() returns 0
问题描述
我认为这是因为用户必须向我的Facebook应用程序授予某种访问权限,以获得getUser可用于我?这是我的代码:
I assume that this is because users have to grant some sort of access to my facebook application, for getUser to be available to me? Here is my code:
<? require 'facebook.php'; ?>
<?php
$facebook = new Facebook(array(
'appId' => '[//fb app id]',
'secret' => '[//fb app secret]',
'cookie' => true
));
$uid = $facebook->getUser();
echo $uid;
?>
所以我猜我的问题是,没有提示用户给我的应用许可,是不是任何其他类型的唯一标识符,我可以从fb用户抓取,以防止他们提交超过1条目到我的应用程序。我有用户的添加提交,但我只想允许每个用户1提交。感谢您的帮助!
So I guess my question is, short of prompting the user to give permission to my app, is there any other sort of unique identifier that I can grab from a fb user to prevent them from submitting more than 1 entry to my app. I have user's add submissions, but I only want to allow 1 submission per user. Thanks for the help!
推荐答案
要获取用户ID,用户必须授予权限
To get user id, user have to grant permission
if($uid){
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}else{
$loginUrl = $facebook->getLoginUrl();
echo("<br>login url=".$loginUrl);
};
在用户授予权限(请参阅loginUrl)后,您可以访问用户ID
After the user grant permission (see the loginUrl), you may access user id
这篇关于facebook-> getUser()返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!