开发者

Facebook connect trouble

开发者 https://www.devze.com 2023-04-13 05:27 出处:网络
I\'ve been struggeling with the facebook connect for a few days now, I\'m only using the PHP SDK downloaded from facebook.

I've been struggeling with the facebook connect for a few days now, I'm only using the PHP SDK downloaded from facebook.

I first used some custom code, but after that failed I just copied the code on facebook, but this still f开发者_如何学Goails.

Is there anything I do wrong? I've created an app on facebook, added the right domain (I get redirected correctly). Once people login, this is the URL they get redirected to:

http://www.mysite.com/index.php?state=33e35654a84559d246c152ed10e8150b&code=AQBGxCMu4vgbw5HgU8EIoyq8rhuHaKvtJQR-VbPMVH8bd2JMIRcxojqJ-l7XrjIdG9TNN05el14Jv8isbHbUWj9so-CdhaEqj7tLR-Rj6-JaOTA7QErrpfN_0XQN1CGCmvmTL6ZtoUupgkVwkzq_CWDT9lSoDPvNHu2F67Jqlsi2DfQZGE1J7pDzujBoSoJhDhs#_=_

The code I copied from facebook:

 <?
  // 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('classes/facebook/facebook.php');

  $config = array(
    'appId' => 'appID here',
    'secret' => 'secret here',
  );

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

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


It turns out it had something to do with the certificate, after some looking around I found out that changing

if (curl_errno($ch) == 60) { 
      // CURLE_SSL_CACERT 

to

if (curl_errno($ch) == 60 || curl_errno($ch) == 77) { 
      // CURLE_SSL_CACERT 

solves the problem

0

精彩评论

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

关注公众号