【发布时间】:2015-05-15 22:16:33
【问题描述】:
我正在制作一个在 Google App Engine 上运行的 PHP 应用程序,并且我正在尝试实现 Facebook 登录。
访问登录网页后,我被重定向到 Facebook,在我接受登录应用程序并被重定向后,我收到错误“错误:此 curl 实现不支持选项 10065。”
我启用了 curl_lite,我暂时在 localhost 上运行它。这是我的代码:
<?php
session_start(); //Session should be active
#region Settings
$app_id = 'xxxxxxx'; //Facebook App ID
$app_secret = 'yyyyyyy'; //Facebook App Secret
$required_scope = 'public_profile'; //Permissions required
$redirect_url = 'http://localhost:8080/signup_fb.php'; //FB redirects to this page with a code
#endregion
#region Imports
//include autoload.php from SDK folder, just point to the file like this:
require_once "../libraries/facebook-php-sdk-v4-4.0-dev/autoload.php";
//import required class to the current scope
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\FacebookRequestException;
use Facebook\GraphUser;
use Facebook\FacebookRedirectLoginHelper;
#endregion
FacebookSession::setDefaultApplication($app_id , $app_secret);
$helper = new FacebookRedirectLoginHelper($redirect_url);
//try to get current user session
try {
$session = $helper->getSessionFromRedirect();
} catch(FacebookRequestException $ex) {
die(" Error : " . $ex->getMessage());
} catch(\Exception $ex) {
die(" Error : " . $ex->getMessage());
}
if ($session){ //if we have the FB session
$user_profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
//do stuff below, save user info to database etc.
echo $user_profile->getProperty('name');
}else{
//display login url
$login_url = $helper->getLoginUrl( array( 'scope' => $required_scope ) );
echo '<a href="'.$login_url.'">Login with Facebook</a>';
}
感谢您的回答:)
【问题讨论】:
-
它抱怨这一行:github.com/facebook/facebook-php-sdk-v4/blob/…。您将不得不更改 SDK 或使用真实版本的 curl
-
您可以使用此处所述的 php.ini 文件启用完整 cURL。 cloud.google.com/appengine/docs/php/#PHP_cURL_support
标签: php facebook google-app-engine curl