Facebook图形api总是返回错误:无法连接到graph.facebook.com端口443:网络无法访问

时间:2016-03-13 13:12:15

标签: php facebook facebook-graph-api

我正在使用Facebook的重定向助手。

帮助程序工作正常,但在login-callback.php中发生错误。 这是我的login-callback.php

<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once 'functions.php';                       //a file I require         

session_start();

$fb = new Facebook\Facebook([
  'app_id' => 'xxxx',
  'app_secret' => 'xxxx',
  'default_graph_version' => 'v2.5',
]);

$helper = $fb->getRedirectLoginHelper();

try {
  $accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

if (isset($accessToken)) {
  $_SESSION['facebook_access_token'] = (string) $accessToken;

  try {
  $response = $fb->get('/me?fields=id,name,email', $accessToken);

} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$user = $response->getGraphUser();

$name=$user['name'];

$id = $user->getId();

$email = $user->getEmail();    

$id='f'.$id;

$result=queryMysql("SELECT * FROM user WHERE id='".$id."'");

if(!$result->num_rows)
 {
  $result=queryMysql("INSERT INTO user VALUES('$id','$name','$email')");
 }
$_SESSION['logger']='facebook';
header('Location: http://localhost/fee/index.php');

}
?>

Graph api和$ helper-&gt; accessToken给出了以下错误。

有时$ helper-&gt; accessToken有效,我接收访问令牌,但图api无效。

我得到的错误是: Facebook SDK返回错误:无法连接到graph.facebook.com端口443:网络无法访问

0 个答案:

没有答案