getUser始终返回0 [英] getUser always returns 0

查看:99
本文介绍了getUser始终返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这段代码有疑问,我到处搜索但没有得到关于此问题的答案.这是我的代码

I have a problem with this piece of code, I search everywhere but didn't get answer for this problem. It's my code

 <?php

      require_once('facebook.php');


      $facebook = new Facebook(array(
        'appId'  => 'XXXXXXXXXXXXXXX',
        'secret' => 'XXXXXXXXXXXXXXX',
        ));

      $user_id = $facebook->getUser();

        echo $user_id;
    ?>

即使我使用自己的帐户登录Facebook时,此代码每次都返回0,有人可以帮助我解决此问题或解释错误吗?我正在使用facebook-php-sdk-v3.1.1-21

This code everytime returns 0 even when I'm logged in on facebook with my account, can someone help me to fix this problem or explain what's wrong? I'm using facebook-php-sdk-v3.1.1-21

我想做这样的事情,在注册表格中要添加Facebook这样的按钮,当用户单击此按钮时,他成为我的Facebook粉丝页面的粉丝,如果他不喜欢按钮脚本,则必须对此进行检查并输出错误,在用户注册之前必须按下按钮,有人可以给我一些技巧或脚本来用PHP实现这一点吗?

I want to make something like this, in registration form want to add facebook like button, when user click on this button he become fan of my facebook fan page, if he don't hit like button script must check for this and output error, that before user can register must hit like button, can someone give me some tips or piece of script how to realize this with PHP?

推荐答案

我遇到了同样的问题,经过很长时间尝试找出问题所在后,我发现您需要访问令牌才能获取用户ID.要从signed_request获取访问令牌,用户必须首先授权(获得许可)您的应用程序.我希望这会有所帮助

I had same issue, After long time of trying to figure out what the issue is, I found that you need access token to get user ID. To get access token form the signed_request, user must authorize (to get permissions) you app firstly. I hope this will help

这篇关于getUser始终返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆