简体   繁体   中英

I want to get the user id but when i open the page , it shows 0

Im new at php and Facebook Sdk , and i want to get the users id. I used this Code

<?php
session_start();
require_once 'facebook.php';
$app_id = " 192181400960374";
$app_secret = "1491eddfb575c07e586515b4d5397953";
$fb_app_url = "nemanjatools.boxhost.me";
$facebook = new Facebook(array(
'appId'  => $fb_app_id,
'secret' => $fb_secret,
'cookie' => true,
));

$facebook_login_url = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'scope' => 'publish_stream,user_photos',
'redirect_uri' => $fb_app_url
));

echo $facebook_user_id = $facebook->getUser();




?>

And when i open the file , it only shows 0. I cant see where is the error , please help me.

您需要facebook_login_url指向链接,而用户需要单击该链接,当前它什么都不做。

add this before the last line

if (!$facebook->getUser()){  
 exit("<script>top.location.href=\"". 
$facebook->getLoginUrl(array('redirect_uri'=>$fb_app_url))."\"</script>");
}

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