Php Google登录和后端身份验证
我遵循了GoogleSignin的教程,它在客户端工作得很好。我已经尝试导出令牌服务器端,但在config.php文件中不断出现500错误。我变得糊涂了:/如果你能看到我在努力做什么,我错过了什么 config.phpPhp Google登录和后端身份验证,php,reactjs,google-signin,Php,Reactjs,Google Signin,我遵循了GoogleSignin的教程,它在客户端工作得很好。我已经尝试导出令牌服务器端,但在config.php文件中不断出现500错误。我变得糊涂了:/如果你能看到我在努力做什么,我错过了什么 config.php <?php //config.php session_start(); require_once('../vendor/autoload.php'); $google_client = new Google_Client(); $googl
<?php
//config.php
session_start();
require_once('../vendor/autoload.php');
$google_client = new Google_Client();
$google_client->setClientId($CLIENT_ID);
$google_client->setClientSecret($CLIENT_SECRET);
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$google_client->setRedirectUri($redirect_uri);
$google_client->addScope('email');
$google_client->addScope('profile');
?>
已解决:)
我有几个问题:
$CLIENT\u ID
和$CLIENT\u SECRET
从哪里来?请将它们设置为正确的Google凭据:)不确定为什么它会因为缺乏研究而被否决-我已经探索了Google API,遵循了一些教程,我只是被这个axios帖子卡住了。注意:我已经更新了今天测试中的一些代码,当前我在本地测试时从外部服务器获得了net::ERR_CONNECTION_densed]500。您检查了服务器上的错误日志了吗?$client
在哪里实例化?
<?php
include('config.php');
if (isset($_POST['code'])) {
$token = $client->fetchAccessTokenWithAuthCode($_POST['code']);
if(!isset($token['error'])){
$google_client->setAccessToken($token['access_token']);
$_SESSION['access_token'] = $token['access_token'] ;
$google_service = new Google_Service_0auth2($google_client);
$data = $google_service->userinfo->get();
if(!empty($data[email])){
$_SESSION['user_email'] = $data['email'];
}
}
}
?>
const responseGoogle = response => {
setName(response.profileObj.name);
setUrl(response.profileObj.imageUrl);
const postData = { code: response.tokenId };
// Send a POST request
axios({
method: 'POST',
url: "http://localhost:80/php/createJSON.php",
headers: {
"Access-Control-Allow-Origin": "*"
},
// headers: axiosConfig,
data: postData
})
.then((response) => {
console.log('RESPONSE.DATA '+response.data);
}, (error) => {
console.log(error);
});