未获取 Facebook 用户 ID

发布于 2025-01-05 04:23:29 字数 523 浏览 0 评论 0原文

我正在尝试获取当前登录并使用我的应用程序的用户的 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...
?>

I'm trying to get the Facebook ID of the current user logged in and using my app so that it can be written to a database along with some other information.

I've tested it countless times for myself and it will get my ID and write it to the database, but if I ask someone else to use it... It won't get the ID of the user of my application...

Am I missing any extended permissions for this? This is all I have so far to get the user id.

Thanks.

<?php include ('includes/php/facebook.php'); ?>

<?php

$facebook = new Facebook(array(
  'appId' => 'XXXXXXXXXXXXXXXXX',
  'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX',
));

?>

<?php

    $user = $facebook->getUser();
    $userId = $user;
    //some code here...
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

贪恋 2025-01-12 04:23:29

如果 $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

它包含几个示例。

If $userID is 0 or null, it means that the user is not authenticated.

// 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'));
}

You can download the SDK from http://developers.facebook.com/docs/reference/php/

It contains several examples.

醉城メ夜风 2025-01-12 04:23:29

http://developers.facebook.com/docs/authentication/

默认情况下,会要求用户授权应用程序访问基本功能
公开或默认在 Facebook 上提供的信息。如果
您的应用程序需要的不仅仅是这些基本信息才能运行,您必须
向用户请求特定权限。这是通过以下方式完成的
将范围参数添加到 OAuth 对话请求,后跟逗号
所需权限的分隔列表。下面的例子
展示如何请求访问用户的电子邮件地址及其新闻
饲料:

https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=email,read_stream

http://developers.facebook.com/docs/authentication/

By default, the user is asked to authorize the app to access basic
information that is available publicly or by default on Facebook. If
your app needs more than this basic information to function, you must
request specific permissions from the user. This is accomplished by
adding a scope parameter to the OAuth Dialog request followed by comma
separated list of the required permissions. The following example
shows how to ask for access to user's email address and their news
feed:

https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=email,read_stream
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文