我正在尝试获取当前用户的Facebook ID并使用我的应用程序,以便可以将其与其他一些信息一起写入数据库。
我已经为自己测试了无数次,它会获取我的ID并将其写入数据库,但是如果我让其他人使用它...它将无法获取我的应用程序的用户ID ...
我错过了任何扩展权限吗?这是我到目前为止获取用户ID的全部内容。
感谢。
<?php include ('includes/php/facebook.php'); ?>
<?php
$facebook = new Facebook(array(
'appId' => 'XXXXXXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX',
));
?>
<?php
$user = $facebook->getUser();
$userId = $user;
//some code here...
?>
答案 0 :(得分:1)
如果$ userID为0或null,则表示用户未经过身份验证。
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me/accounts');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl(array("domain" => 'www.myurl.com'));
} else {
$loginUrl = $facebook->getLoginUrl(array("scope" => 'publish_stream,offline_access,manage_pages'));
}
您可以从http://developers.facebook.com/docs/reference/php/
下载SDK它包含几个例子。
答案 1 :(得分:0)
http://developers.facebook.com/docs/authentication/
默认情况下,系统会要求用户授权应用访问基本版 Facebook上公开或默认提供的信息。如果 您的应用程序需要的不仅仅是这些基本信息才能运行 请求用户的特定权限。这是通过 将范围参数添加到OAuth Dialog请求后跟逗号 分隔所需权限的列表。以下示例 显示如何请求访问用户的电子邮件地址及其新闻 饲料:
https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=email,read_stream