Php Facebook SDK V4错误

Php Facebook SDK V4错误,php,facebook,facebook-graph-api,Php,Facebook,Facebook Graph Api,我正在尝试使用Facebook登录我的网站 我的代码在Localhost上运行得非常好。但当我上传到服务器时。它给出如下错误: Facebook\FacebookSDKException Object ( [message:protected] => couldn't connect to host [string:Exception:private] => [code:protected] 您可以尝试演示: 这是我的代码: <?php // include require

我正在尝试使用Facebook登录我的网站

我的代码在Localhost上运行得非常好。但当我上传到服务器时。它给出如下错误:

Facebook\FacebookSDKException Object ( [message:protected] => couldn't connect to host [string:Exception:private] => [code:protected]
您可以尝试演示:

这是我的代码:

<?php

// include required files form Facebook SDK

require 'facebook-php-sdk/autoload.php';

use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;



// start session
session_start();

// init app with app id and secret
FacebookSession::setDefaultApplication( 'abc','xyz' );

// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper( 'http://dkclan.co/facebook_user_authentication.php' );

// see if a existing session exists
if ( isset( $_SESSION ) && isset( $_SESSION['fb_token'] ) ) {
// create new session from saved access_token
$session = new FacebookSession( $_SESSION['fb_token'] );
// validate the access_token to make sure it's still valid
try {
if ( !$session->validate() ) {
$session = null;
}
} catch ( Exception $e ) {
// catch any exceptions
$session = null;
}
}

if ( !isset( $session ) || $session === null ) {
// no session exists
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
// handle this better in production code
print_r( $ex );
} catch( Exception $ex ) {
// When validation fails or other local issues
// handle this better in production code
print_r( $ex );
}
}

// see if we have a session
if ( isset( $session ) ) {
// save the session
$_SESSION['fb_token'] = $session->getToken();
// create a session using saved token or the new one we generated at login
$session = new FacebookSession( $session->getToken() );
// graph api request for user data
$request = new FacebookRequest( $session, 'GET', '/me' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject()->asArray();
// print profile data
echo '<pre>' . print_r( $graphObject, 1 ) . '</pre>';
// print logout url using session and redirect_uri (logout.php page should destroy the session)
echo '<a href="' . $helper->getLogoutUrl( $session, 'http://yourwebsite.com/app/logout.php' ) . '">Logout</a>';
} else {
// show login url
echo '<a href="' . $helper->getLoginUrl( array( 'email', 'user_friends' ) ) . '">Login</a>';
}

您的提供商很可能会阻止传出的CURL调用(Facebook SDK使用CURL调用Facebook API)

请查看具有相同错误的此线程:


这是有意义的,因为它在本地服务器上工作。您唯一能做的就是要求提供商允许调用Facebook API。

可能重复@luschn,但没有提供解决方案。那么你能帮我解决这个问题吗?这并不意味着你应该为完全相同的问题打开另一个线程。永远不要这样做。我删除了那个帖子,然后又发布了一条新的,因为没有人回复我。所以我想下次我应该问你,请坚持你的帖子,不要再转发了,这样“撞”一个帖子是非常糟糕的举动。非常感谢你的回答。我将联系我的服务器提供商