简体   繁体   中英

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

Facebook Page Tab Problem

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.

在此处输入图片说明

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

Then I wanted to retrieve the user's name and user's id " to the user " who will use this page tab app thing.

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 . 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

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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