Facebook登录问题(php sdk 3.1.1 +最新js SDK)

时间:2011-09-13 04:41:31

标签: facebook login facebook-php-sdk

  1. 我创建了test.php
  2. 来自here
  3. 的复制示例
  4. 更改了appId和秘密
  5. 将test.php上载到服务器
  6. 试图登录
  7. 我得到一个例外“必须使用活动访问令牌来查询有关当前用户的信息”

    请帮助我这个人..已经5天了,我对此无能为力。

4 个答案:

答案 0 :(得分:2)

我多次遇到同样的问题。试试这个:

public static $CURL_OPTS = array(
   CURLOPT_CONNECTTIMEOUT => 100,//-----increase this value
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_TIMEOUT        => 600,//-----increase this value
   CURLOPT_USERAGENT      => 'facebook-php-3.1',

 );

答案 1 :(得分:1)

只是为了添加原始问题,我只是复制了normeus发布的代码,将appID和secret更改为我的应用程序的值,并得到以下内容:

You are not Connected.
Fatal error: Uncaught OAuthException: Invalid OAuth access token signature. thrown in 
/path/to/my/server/app/address/base_facebook.php on line 1033

当然,在屏幕顶部的facebook栏中,它显示我有1条未读消息,因为我实际登录过。是否还需要进行其他设置?似乎有很多人都有这个问题,但也有很多人没有这个问题没有明确的解决方案。

的Darryl

答案 2 :(得分:0)

如果您发布代码会更容易,因为这听起来像拼写错误。您没有登录Facebook,并且您的页面没有要求您登录,因此您没有获得令牌,并且您收到令牌错误。 这有效:

<?php

// * Copyright 2011 Facebook, Inc.


require '../inc/src/facebook.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
    'appId'  => 'APP ID NUMBER',
    'secret' => 'APP SECRET CODE',
  'scope'  => 'manage_pages,offline_access,publish_stream'
));

// 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');
  } 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();
} else {
  $loginUrl = $facebook->getLoginUrl();
}

?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <head>
    <title>php-sdk</title>
    <style>
      body {
        font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
      }
      h1 a {
        text-decoration: none;
        color: #3b5998;
      }
      h1 a:hover {
        text-decoration: underline;
      }
    </style>
  </head>
  <body>
    <h1>php-sdk </h1>

    <?php if ($user): ?>
      <a href="<?php echo $logoutUrl; ?>">Logout</a>
    <?php else: ?>
      <div>
        Login using OAuth 2.0 handled by the PHP SDK:
        <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
      </div>
    <?php endif ?>

    <h3>PHP Session</h3>
    <pre><?php print_r($_SESSION); ?></pre>

    <?php if ($user): ?>
      <h3>You</h3>
      <img src="https://graph.facebook.com/<?php echo $user; ?>/picture">
      <h3>Your User Object (/me)</h3>
      <pre><?php print_r($user_profile); ?></pre>
    <?php else: ?>
      <strong><em>You are not Connected.</em></strong>
    <?php endif ?>
    <?php
    $args = array(
    'message'   => 'Garage Band!',
    'link'      => 'http://www.fancyapps.com/',
    'caption'   => 'Looking for 1000s og visitors!'
);
    $facebook->api("/me/feed", "post", $args); ?>
  </body>
</html>

答案 3 :(得分:0)

我找到了解决方案。

我添加了CURLOPT_SSL_VERIFYPEER =&gt; 0到基础facebook类。

public static $CURL_OPTS = array(
    CURLOPT_CONNECTTIMEOUT => 10,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 60,
    CURLOPT_USERAGENT      => 'facebook-php-3.1',
    CURLOPT_SSL_VERIFYPEER => 0
  );