【问题标题】:Facebook PHP SDK error [duplicate]Facebook PHP SDK错误[重复]
【发布时间】:2014-01-24 13:36:03
【问题描述】:

我已经用 facebook 开发者帐户注册了新应用程序。按照教程,我有这个代码:

    <?php
  // Remember to copy files from the SDK's src/ directory to a
  // directory in your application on the server, such as php-sdk/
  require_once('facebook/facebook.php');

  $config = array(
    'appId' => 'xxxxxxxxxxxx',
    'secret' => 'yyyyyyyyyyyyyy',
    'allowSignedRequest' => false // optional but should be set to false for non-canvas apps
  );

  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();
?>
<html>
  <head></head>
  <body>

  <?php
    if($user_id) {

      // We have a user ID, so probably a logged in user.
      // If not, we'll get an exception, which we handle below.
      try {

        $user_profile = $facebook->api('/me','GET');
        echo "Name: " . $user_profile['name'];

      } catch(FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        $login_url = $facebook->getLoginUrl(); 
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
      }   
    } else {

      // No user, print a link for the user to login
      $login_url = $facebook->getLoginUrl();
      echo 'Please <a href="' . $login_url . '">login.</a>';

    }

  ?>

  </body>
</html>

我在应用仪表板上设置: 应用程序域:buzzsu.com 网址:buzzsu.com

然后我将上面的代码放在 www.buzzsu.com 中。当我访问该页面时,它会提供我登录。当我点击登录时,它给了我以下错误:

Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.

我该如何解决?

【问题讨论】:

  • 在仪表板上,您添加了buzzsu.com 还是www.buzzsu.com?这很重要。
  • 好的!我为 www.buzzsu.com 编辑了应用程序设置。然后在Firefox中我输入了buzzsu.com它没有工作,在我尝试输入www.buzzsu.com并且它工作之后。有什么问题?

标签: php facebook facebook-graph-api


【解决方案1】:

我遇到了同样的问题,我发现我的“redirect_uri”和“有效的 OAuth 重定向 URI”不匹配。

在我的代码中,我设置了:

redirect_uri = "http://www.website.com/validate.php";

但在我的 Facebook 应用中,我设置了有效的 OAuth 重定向 URI:

http://website.com/validate.php

我所缺少的只是“www”。所以我在我的 Facebook 应用中添加了另一个有效的 OAuth 重定向 URI:

http://www.website.com/validate.php




我的工作对我来说就像魔术一样。
希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2014-07-31
    • 2011-11-15
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多