我正在使用 SDK php 让用户使用他们的 Facebook 帐户登录我的网站。我正在关注 SDK 示例。当我试图获取登录的用户 ID 时,它返回 0:
$id = $facebook->getUser();
你能告诉我有什么问题吗,以及如何使用 php SDK 使示例工作
这是示例的代码:
<?php
$config = FacebookConfig::getConfig();
$facebook = new Facebook( $config );
$user = $facebook->getUser();
Facebook::$CURL_OPTS[ CURLOPT_SSL_VERIFYPEER ] = false;
if ( $user ) {
try {
$user_profile = $facebook->api( '/me' );
$logoutUrl = $facebook->getLogoutUrl();
}
catch ( FacebookApiException $e ) {
error_log( $e );
$user = null;
}
} else {
try {
$loginUrl = $facebook->getLoginUrl( array(
"scope" => "email,user_education_history,user_work_history",
"redirect_uri" => "http://localhost:8888/www/index.php"
) );
$user = $facebook->getUser();
$user_profile = $facebook->api( '/me' );
$userProf = $facebook->api( "/$user" );
echo $user;
echo $user_profile;
}
catch ( FacebookApiException $e ) {
$user = null;
echo "expetion in login";
}
}
?>