嗨,每一个我只是得到这个错误:无法连接到255.255.255.255:网络无法访问

时间:2014-09-03 16:43:48

标签: php facebook-graph-api sdk

  1. 我只是使用facebook php sdk v3.2.3
  2. 错误类型:curl exception ...
  3. 我只是使用卷曲主机,但它不起作用......
  4. 这是我的代码:

      <?php 
      require 'facebook.php';
      $facebook = new Facebook(array(
        'appId'  => '',
        'secret' => ''
     ));
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8" />
    <title>Facebook PHP</title>
    </hea    <body>
    <h1>Hello World</h1>
    <?php
    //get user from facebook object
    $user = $facebook->getUser();
    
    if ($user): //check for existing user id
     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>';
    
         echo '<p>getType: ',$e->getType(), '</p>';;
        echo '<p>getMessage: ',$e->getMessage(), '</p>';;
      }  
    
        echo '<p>User ID: ', $user, '</p>';
    
        //print logout link
        echo '<p><a href="logout.php">logout</a></p>';
         else: //user doesn't exist
        $loginUrl = $facebook->getLoginUrl(array(
            'diplay'=>'popup',
            'scope'=>'email',
            'redirect_uri' => 'http://apps.facebook.com/blabla'
           ));
            echo '<p><a href="', $loginUrl, '" target="_top">login</a></p>';
         endif; //check for user id
           ?>
        </body>
        </html>
    

1 个答案:

答案 0 :(得分:0)

只需进行一些修改即可解决,我GUESS(猜猜看,因为我还没看到facebook.php)

<?php 
require 'facebook.php';
$facebook = new Facebook(array('appId' => '', 'secret' => ''));
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Facebook PHP</title>
</head>
<body>
<h1>Hello World</h1>
<?php
//get user from facebook object
$user = $facebook->getUser();

if ($user): //check for existing user id
 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>';

    echo '<p>getType: ',$e->getType(), '</p>';;
    echo '<p>getMessage: ',$e->getMessage(), '</p>';;
  }  

    echo '<p>User ID: ', $user, '</p>';

    //print logout link
    echo '<p><a href="logout.php">logout</a></p>';
     else: //user doesn't exist
    $loginUrl = $facebook->getLoginUrl(array(
        'diplay'=>'popup',
        'scope'=>'email',
        'redirect_uri' => 'http://apps.facebook.com/blabla'
       ));
        echo '<p><a href="', $loginUrl, '" target="_top">login</a></p>';
     endif; //check for user id
      ?>
  </body>
  </html>

让我们看看会发生什么,我们在这里调整,保持联系。