开发者

Facebook login issue (php sdk 3.1.1 + latest js SDK)

开发者 https://www.devze.com 2023-04-04 05:25 出处:网络
I\'ve created test.php Copied exa开发者_Go百科mple from here Changed appId, and secret Uploaded test.php to server
  1. I've created test.php
  2. Copied exa开发者_Go百科mple from here
  3. Changed appId, and secret
  4. Uploaded test.php to server
  5. Tried to login

And I get an exception "An active access token must be used to query information about the current user"

Please help me someone with this.. It's already 5 days I can't do anything with this.


I encountered the same problem many times. Try this:

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',

 );


Just to add to the original question, I just copied the code posted by normeus, changed the appID and secret to the values for my application, and got the following:

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

Of course in the facebook bar at the top of the screen it shows that I have 1 unread message since I'm actually logged in. Is there some other setting that needs to be made? It seems like there are a lot of people with this issue, but also a lot who don't have it with no definitive solution.

Darryl


It will be easier if you posted code since this sounds like a typo. you are not logged into Facebook and your page is not asking you to login so you are not getting a token and you get a token error. This works:

<?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>


I've found a solution.

I've added CURLOPT_SSL_VERIFYPEER => 0 to base facebook class.

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

精彩评论

暂无评论...
验证码 换一张
取 消