我在我的网站上插入了“谷歌一键”,然后谷歌返回给我"credential“和"g_csrf_token”的POST方法。现在我想知道,我如何在PHP中从这个“凭证”中获得电子邮件地址?
有没有用于Codeigniter 4的PHP库或模块?
我在前台只有这个:
<script src="https://accounts.google.com/gsi/client" async defer></script>
<div id="g_id_onload" data-client_id="000.apps.googleusercontent.com" data-login_uri="https://myweb.com/google"></div>在后台文件"myurl/google“中
print_r($_POST);谢谢
发布于 2021-07-25 00:11:51
下面是获取它的方法:
<?php
$token=$_POST["credential"];
print_r(json_decode(base64_decode(str_replace('_', '/', str_replace('-','+',explode('.', $token)[1])))));
?>发布于 2021-11-13 15:19:24
根据这篇文档,我们是如何获得它的:
这里
还有这里:
// Firstly, create Google client object with client ID
$google_client = new Google_Client([
'client_id' => YOUR_CLIENT_ID
]);
// Then, verify the credential
$token = $_POST['credential'];
$payload = $google_client->verifyIdToken($token);
if ($payload && $payload['aud'] == YOUR_CLIENT_ID)
{
// Here you can get user email from Google, Also you can get all user data
$email = $payload['email'];
// Lastly, you can add user email to session, Or any thing you want in your app
$_SESSION['user'] = $email;
}https://stackoverflow.com/questions/67140189
复制相似问题