针对新版本的 facebook PHP SDK 在应用程序中进行的更改

发布于 2024-12-23 07:59:03 字数 92 浏览 0 评论 0原文

我们正在使用旧版本的 Facebook connect PHP SDK,我们需要做哪些更改才能使应用程序适应新的更改(由于 FB 应用程序版本更改,目前应用程序无法运行)

We are using old version of Facebook connect PHP SDK, what changes we need to do to make the app working with the new changes (Currently the app is not working due to FB app version changes)

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

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

发布评论

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

评论(2

居里长安 2024-12-30 07:59:03

更新您的 PHP SDK,连接需要更改,getSession() 没有如果不再可用,请改用 getUser()。另外,如果您使用的 PHP SDK 太旧(在 Graph API 之前),那么您可能需要更新一些 API 调用函数。

整体连接如下:

$facebook = new Facebook(array(
  'appId'  => '111111111',// your appId here
  'secret' => '1a1a1a1a1a1a1',// your app secret here
));


$user = $facebook->getUser();

if ($user) {
  try {
    $user_profile = $facebook->api('/me');

  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();



} else {
  $loginUrl = $facebook->getLoginUrl();
    echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
    exit;
}

Update your PHP SDK, connection needs change, getSession() is no longer available, use getUser() instead. Also if you are using too old PHP SDK (before Graph API) then you may have to update some API calling functions.

Overall connection is like below:

$facebook = new Facebook(array(
  'appId'  => '111111111',// your appId here
  'secret' => '1a1a1a1a1a1a1',// your app secret here
));


$user = $facebook->getUser();

if ($user) {
  try {
    $user_profile = $facebook->api('/me');

  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();



} else {
  $loginUrl = $facebook->getLoginUrl();
    echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
    exit;
}
苍白女子 2024-12-30 07:59:03

简短回答:身份验证流程和 REST API 弃用

长回答:自 2.1 版以来,有两个主要版本更改。您应该浏览Facebook 开发者博客以清楚地了解更改。

以下是一些公告链接:

  1. 开发者路线图更新:转向 OAuth 2.0 + HTTPS
  2. 升级到 PHP SDK v3.0.0
  3. 迁移到 OAuth 2.0 更新:PHP SDK v.3.1.1

使用 PHP 的新登录流程SDK 看起来像这样:

$facebook = new Facebook(…);
$user = $facebook->getUser();
if ($user) {
  // proceed knowing you have a logged in user who's authenticated
} else {
  // proceed knowing you require user login and/or authentication
}

如果您当前正在存储会话密钥,它们将不再起作用。您需要迁移以使用 oauth 访问令牌。此 SO 链接讨论了此过程: Converting Facebook session key to access tokens

另外,如果您的画布应用程序使用旧版身份验证,您需要按照本页所述进行更改:迁移到 OAuth 2.0

Short answer: authentication flow and REST API deprecation

Long answer: there have been two major version changes since version 2.1. You should go through the facebook developer blog for clear understanding of changes.

Some of the announcement links below:

  1. Developer Roadmap Update: Moving to OAuth 2.0 + HTTPS
  2. Upgrade to PHP SDK v3.0.0
  3. Migrating to OAuth 2.0 update: PHP SDK v.3.1.1

The new login flow using PHP SDK looks like this:

$facebook = new Facebook(…);
$user = $facebook->getUser();
if ($user) {
  // proceed knowing you have a logged in user who's authenticated
} else {
  // proceed knowing you require user login and/or authentication
}

If you are storing session keys at the moment, they will not work anymore. You'll need to migrate to use oauth access tokens. This SO link discusses this process: Converting Facebook session keys to access tokens

Also, if yours is a canvas app using legacy auth, you'll need to make changes as described on this page: Migrating to OAuth 2.0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文