简体   繁体   English

Facebook PHP SDK $ facebook-> getSignedRequest()获取用户ID和名称。 (页面标签)

[英]Facebook PHP SDK $facebook->getSignedRequest() Get User ID and Name. (Page Tab)

Facebook Page Tab Problem Facebook页面标签问题

Well, I don't know how to say this, I want to retrieve the user's id and user's name on the page tab of facebook. 好吧,我不知道怎么说,我想在facebook的页面选项卡上检索用户的ID和用户名。

在此处输入图片说明

Then when you clicked the Application where the arrow points it should look like this. 然后,当您单击“应用程序”时,箭头指向的位置应如下所示。

在此处输入图片说明

I don't get it why the Page Admin and Page Like is 1 it should output the ID of the users right? 我不明白为什么“ 页面管理员”和“页面赞”为1,它应该正确输出用户ID吗? and why the UserID is 0 ? 为什么UserID为0 I logged on and I already liked the page 我登录并且已经喜欢了该页面

Then I wanted to retrieve the user's name and user's id " to the user " who will use this page tab app thing. 然后,我想检索将使用此页面选项卡应用程序对象的用户名和用户ID“ 给用户 ”。

Here is my code for that. 这是我的代码。

if(!@include("../sdk/facebook.php")) throw new Exception("Failed to include 'facebook.php'");
$app_id = "xxx"; // Your application id
$app_secret = "xxx"; // Your application secret
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signedrequest = $facebook->getSignedRequest();
$fbp_id = $signedrequest["page"]["id"]; //Facebook Fan Page ID
echo $is_admin = $signedrequest["page"]["admin"]; echo " Page Admin <br>";
echo $is_liked = $signedrequest["page"]["liked"]; echo " Page Liked<br>";
echo $uid=$facebook->getUser(); echo " User ID<br>";

Well I can retrieve the Fan Page ID, using the $fbp_id still, I can't retrieve the user's id it only outputs 0 . 好吧,我仍然可以使用$ fbp_id来检索粉丝页面ID,但是我不能检索用户ID, 它只能输出0 How can I retrieve it? 我如何找回它? Any solution for this? 有什么解决办法吗?

Would be glad if you help me. 如果您能帮助我,会很高兴。

First of all You must take a permission from your user to get his/her data. 首先,您必须获得用户的许可才能获取其数据。 There are two ways you can do that the best way will be 您有两种方法可以做到最好,

$loginUrl = $facebook->getLoginUrl(
 array(
 'redirect_uri' => $your_page_tab_url,
 'scope'  => 'email'
      )

After getting this url check if the user_id is 0 than redirect him to 获取此网址后,请检查user_id是否为0,然后将其重定向到

<script type='text/javascript'>top.location.href = '$loginUrl';</script>

but one more thing this is for the new PHP sdk so you will have to update the one you have 但是还有一件事是用于新的PHP sdk,因此您将不得不更新拥有的一个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM