facebook->getUser() returns 0

纵饮孤独 提交于 2019-12-19 09:47:01

问题


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;

 ?>

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!


回答1:


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);
};

After the user grant permission (see the loginUrl), you may access user id



来源:https://stackoverflow.com/questions/8184199/facebook-getuser-returns-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!