<body>
<script src="; async defer></script>
<div id="g_id_onload"
data-client_id="790854323959-v2lniefhl7ripoijm0ooetu9ari91g3q.apps.googleusercontent"
data-callback="handleCredentialResponse">
</div>
<div class="g_id_signin" data-type="standard"></div>
<script>
function handleCredentialResponse(response) {
// decodeJwtResponse() is a custom function defined by you
// to decode the credential response.
const responsePayload = decodeJwtResponse(response.credential);
console.log("ID: " + responsePayload.sub);
console.log('Full Name: ' + responsePayload.name);
console.log('Given Name: ' + responsePayload.given_name);
console.log('Family Name: ' + responsePayload.family_name);
console.log("Image URL: " + responsePayload.picture);
console.log("Email: " + responsePayload.email);
}
</script>
</body>
Note: I want to integrate google login in php project using javascript. But I am getting error like- decodeJwtResponse is not defined at Nn.handleCredentialResponse [as callback]. Please help me, I want to get profile details. please provide me all the details regarding my query.
<body>
<script src="https://accounts.google./gsi/client" async defer></script>
<div id="g_id_onload"
data-client_id="790854323959-v2lniefhl7ripoijm0ooetu9ari91g3q.apps.googleusercontent."
data-callback="handleCredentialResponse">
</div>
<div class="g_id_signin" data-type="standard"></div>
<script>
function handleCredentialResponse(response) {
// decodeJwtResponse() is a custom function defined by you
// to decode the credential response.
const responsePayload = decodeJwtResponse(response.credential);
console.log("ID: " + responsePayload.sub);
console.log('Full Name: ' + responsePayload.name);
console.log('Given Name: ' + responsePayload.given_name);
console.log('Family Name: ' + responsePayload.family_name);
console.log("Image URL: " + responsePayload.picture);
console.log("Email: " + responsePayload.email);
}
</script>
</body>
Note: I want to integrate google login in php project using javascript. But I am getting error like- decodeJwtResponse is not defined at Nn.handleCredentialResponse [as callback]. Please help me, I want to get profile details. please provide me all the details regarding my query.
Share Improve this question edited Aug 2, 2022 at 17:16 asked Aug 2, 2022 at 16:50 user19165954user191659542 Answers
Reset to default 10This will work with a valid response
function decodeJwtResponse(token) {
var base64Url = token.split(".")[1];
var base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
var jsonPayload = decodeURIComponent(
atob(base64)
.split("")
.map(function (c) {
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
})
.join("")
);
return JSON.parse(jsonPayload);
}
The answer is right there in the code you copied from Google.
// decodeJwtResponse() is a custom function defined by you
// to decode the credential response.
You need to define the function yourself to decode the CredentialResponse.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745094235a4610877.html
评论列表(0条)