卷曲错误:如何重新启用它?(Facebook Auth)
Posted
技术标签:
【中文标题】卷曲错误:如何重新启用它?(Facebook Auth)【英文标题】:Curl Error: How can I re-enable it?(Facebook Auth) 【发布时间】:2015-09-13 19:10:50 【问题描述】:在本地主机上运行代码时,它运行良好,在服务器上运行相同时,它不会重定向,在成功登录 Facebook 后,重定向不起作用。
服务器 php 5.4.x Facebook PHP SDK v4
1. PHP Warning: curl_exec() has been disabled for security reasons in /src/Facebook/HttpClients/FacebookCurl.php on line 77
2. PHP Catchable fatal error: Argument 4 passed to Facebook\FacebookResponse::__construct() must be of the type array, null given, called in src/Facebook/FacebookClient.php on line 225 and defined in /src/Facebook/FacebookResponse.php on line 75
源代码
fbconfig.php
<?php
require_once 'src/Facebook/autoload.php';
use Facebook\Facebook;
use Facebook\FacebookResponse;
use Facebook\GraphNodes\GraphUser;
use Facebook\Exceptions\FacebookAuthenticationException;
use Facebook\Exceptions\FacebookSDKException;
use Facebook\Exceptions\FacebookResponseException;
use Facebook\Helpers\FacebookRedirectLoginHelper;
use Facebook\FacebookClient;
use Facebook\HttpClients\FacebookHttpClientInterface;
session_start();
$fb = new Facebook(['app_id' => 'xx',
'app_secret' => 'yy',
'default_graph_version' => 'v2.2',
]);
$helper = $fb->getRedirectLoginHelper();
try
$accessToken = (string)($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;
echo $accessToken;
if (isset ($accessToken))
$fb->setDefaultAccessToken($accessToken);
try
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('/me');
$user = $response->getGraphUser();
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;
$_SESSION['FULLNAME']=$user['name'];
$_SESSION['FBID']= $user['id'];
header("Location: index.php");
else
$permissions = ['email']; // optional
$loginUrl = $helper->getLoginUrl("http://x.com/fbconfig.php",$permissions);//,$permissions);
header("Location: ".$loginUrl);
?>
如何在服务器中启用curl_exec()
?这是什么curl_exec()
【问题讨论】:
【参考方案1】:如警告所述,curl_exec()
已禁用。 Curl 用于与 facebook 通信并且是必需的,因此请确保您或您的托管服务提供商启用它。
【讨论】:
以上是关于卷曲错误:如何重新启用它?(Facebook Auth)的主要内容,如果未能解决你的问题,请参考以下文章
使用ShareFile FTP Link的Facebook商品Feed计划 - 卷曲错误56
Azure Bot服务Facebook Messenger回调URL提供404
PHP中的Facebook Graph API出现不一致的错误 - 无法连接到graph.facebook.com端口443:连接超时