无法连接到graph.facebook.com端口443:网络不可达 [英] Failed to connect to graph.facebook.com port 443: Network unreachable

查看:664
本文介绍了无法连接到graph.facebook.com端口443:网络不可达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php
session_start();

//included file and use

$app_id = 'xxx';
$app_secret = 'xxx';
FacebookSession::setDefaultApplication($app_id, $app_secret);
$helper = new FacebookRedirectLoginHelper("`http://example/facebook4.0`/", $app_id, $app_secret);
try 
{
    $session = $helper->getSessionFromRedirect();
}
catch(FacebookRequestException $ex) { } 
catch(Exception $ex) { }

$loggedIn = false;

if (isset($session))
{
    if ($session) 
        {
            $loggedIn = true;
            try {                     //logged here and get data
                $user_profile = (new FacebookRequest(
                $session, 'GET', '/me'
                ))->execute()->getGraphObject(GraphUser::className());

               print_r($user_profile); //print data

            } 
            catch(FacebookRequestException $e)  {
                echo "Exception occured, code: " . $e->getCode();
                echo " with message: " . $e->getMessage();
            }   
        }
}

if(!$loggedIn)  //if user is not online // get link and add scope
{
    $loginUrl = $helper->getLoginUrl(array('public_profile','email'));
    echo "<a href='$loginUrl'>Login With Facebook</a>";
}
else
{
    print_r($user_profile); //logout link is generated here 
    echo '<br><br><a href="index.php">Logout</a>'; //print to sceen
}

?>

我已将域名设置为localhost和站点URL到 http://本地主机/
我也尝试过 http:// localhost:80 http:// mydomainname:80 更改主机)

I have set Domain name to localhost and Site URL to http://localhost/. I have also tried http://localhost:80 , http://mydomainname:80 (changing hosts)

这是我收到的错误:

Facebook\FacebookSDKException Object
(
    [message:protected] => Failed to connect to graph.facebook.com port 443: Network unreachable
    [string:Exception:private] => 
    [code:protected] => 7
    [file:protected] => C:\xampp\htdocs\myapp\Facebook\HttpClients\FacebookCurlHttpClient.php
    [line:protected] => 142
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => C:\xampp\htdocs\myapp\Facebook\FacebookRequest.php
                    [line] => 248
                    [function] => send
                    [class] => Facebook\HttpClients\FacebookCurlHttpClient
                    [type] => ->
                    [args] => Array
                        (
                            [0] => https://graph.facebook.com/v2.0/oauth/access_token?client_id='my key'&redirect_uri=http%3A%2F%2Flocalhost%3A80%2Fmyapp%2F&client_secret='mykey_secert'&code=AQCYmzsFNUIQG7gUAZ3y-YJHLeIGcF-xyqHotx31MCJGlm16fV9VbVSzlGlx5280-u0Ho3jFjg_REevN5J0LEIPHerY1QaaBYjpkkoIMf6PCwHGj2OIrQDvfyGcUJRK4cJP0YQ8H8HdYw86xEhlcdJHvnObkCU6tSBcVbDWM8uoXJlRqNl6o-IdxoSfbk6IjuCreyagMXvam4vgV0HKxn0nkWaV26k1P6kQP_L1LtXXx2UyUQ1i0jJGL9JiGr1gsUbf5drY_URIrEWzawumpnSWkuxln8hiOtAr_xwM_4cBZwxf3_pWq8YnUotpmzzM5sPhW_ERMYWAdovjZPHu7Xdgs&access_token=329734847193179%7Cd9e5cdb2d0c3cbe1e127827762e94284&appsecret_proof='key_proof'
                            [1] => GET
                            [2] => Array
                                (
                                )    
                        )    
                )

            [1] => Array
                (
                    [file] => C:\xampp\htdocs\myapp\Facebook\FacebookRedirectLoginHelper.php
                    [line] => 146
                    [function] => execute
                    [class] => Facebook\FacebookRequest
                    [type] => ->
                    [args] => Array
                        (
                        )    
                )

            [2] => Array
                (
                    [file] => C:\xampp\htdocs\myapp\index.php
                    [line] => 52
                    [function] => getSessionFromRedirect
                    [class] => Facebook\FacebookRedirectLoginHelper
                    [type] => ->
                    [args] => Array
                        (
                        )    
                )    
        )    
    [previous:Exception:private] => 
)


推荐答案

我知道这是一个老问题和OP可能已经找到了解决方案。在使用 Laravel Socialite 插件的同时,我也遇到了同样的问题。

I know this is an old question and the OP might have already found the solution. I also bumped into the same issue while working with the Laravel Socialite plugin.

对于后代,我想在这里发布解决方案。该问题在此问题中解释:域graph.facebook.com解析为IPV6地址,某些网络可能不是配置路由。您可以请求cURL将IP地址解析为其IPV4值。将选项 CURLOPT_IPRESOLVE 设置为 CURL_IPRESOLVE_V4

For posterity, I would like to post the solution here. The issue is explained in this question: the domain graph.facebook.com resolves to an IPV6 address which some networks may not be configured to route. You can request cURL to resolve IP addresses to their IPV4 values. Set the option CURLOPT_IPRESOLVE to CURL_IPRESOLVE_V4.

在社交名人插件的情况下,我们必须修改 FacebookProvider.php 以包含附加选项。

In the case of the socialite plugin, we had to modify the FacebookProvider.php to include the additional option.

修改

更具体来说,Socialite使用GuzzleHttp,我们需要将其作为参数传递给GuzzleHttp Client方法:

To be more specific, Socialite uses GuzzleHttp, and we need to pass this as a parameter to the GuzzleHttp Client method:

'curl' => [ CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4]

这篇关于无法连接到graph.facebook.com端口443:网络不可达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆