Facebook PHP SDK $ facebook-> getSignedRequest()获取用户ID和名称. (页面标签)
Facebook页面选项卡问题
好吧,我不知道怎么说,我想在facebook的页面标签上检索用户ID和用户名.
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.
然后,当您单击应用程序时,箭头指向它的位置应如下所示.
Then when you clicked the Application where the arrow points it should look like this.
我不明白为什么 Page Admin和Page Like是1 应该正确输出用户ID的原因?为什么用户ID为0 ?我登录并且已经喜欢了该页面
I don't get it why the Page Admin and Page Like is 1 it should output the ID of the users right? and why the UserID is 0? I logged on and I already liked the page
然后,我想检索用户名和用户ID"给用户".谁将使用此页面标签应用程序的东西.
Then I wanted to retrieve the user's name and user's id "to the user" who will use this page tab app thing.
这是我的代码.
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>";
好吧,我仍然可以使用 $ fbp_id 来检索粉丝页面ID,我不能检索用户的ID ,它只能输出0 .我该如何找回它?有什么解决办法吗?
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. 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'
)
获取此网址后,请检查user_id是否为0,然后将其重定向到
After getting this url check if the user_id is 0 than redirect him to
<script type='text/javascript'>top.location.href = '$loginUrl';</script>
但是这是新的PHP sdk的另一件事,因此您将不得不更新自己的新版本
but one more thing this is for the new PHP sdk so you will have to update the one you have