Javascript 我正在使用谷歌API Oauth2在我的网站上进行谷歌登录。如何将此代码中的全名和电子邮件id变量输入php代码?
这是谷歌开发者网站上的代码。我只是这方面的初学者。我不知道如何将这些变量输入php,以便将它们插入数据库Javascript 我正在使用谷歌API Oauth2在我的网站上进行谷歌登录。如何将此代码中的全名和电子邮件id变量输入php代码?,javascript,php,jquery,google-api-client,Javascript,Php,Jquery,Google Api Client,这是谷歌开发者网站上的代码。我只是这方面的初学者。我不知道如何将这些变量输入php,以便将它们插入数据库 <script> if (auth2.isSignedIn.get()) { var profile = auth2.currentUser.get().getBasicProfile(); console.log('ID: ' + profile.getId()); console.log('Full Name: ' + profile
<script>
if (auth2.isSignedIn.get()) {
var profile = auth2.currentUser.get().getBasicProfile();
console.log('ID: ' + profile.getId());
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
}
</script>
if(auth2.isSignedIn.get()){
var profile=auth2.currentUser.get().getBasicProfile();
log('ID:'+profile.getId());
log('Full Name:'+profile.getName());
log('给定名称:'+profile.getGivenName());
console.log('Family Name:'+profile.getFamilyName());
log('Image URL:'+profile.getImageUrl());
log('Email:'+profile.getEmail());
}
使用jquery库,您可以编写如下内容。然后,data.php内的$\u POST变量中将提供所有详细信息。这段代码将为您提供总体思路
if (auth2.isSignedIn.get()) {
var profile = auth2.currentUser.get().getBasicProfile();
userData = {
id: profile.getId(),
name: profile.getName(),
givenName: profile.getGivenName(),
familyName: profile.getFamilyName(),
imageUrl: profile.getImageUrl(),
email: profile.getEmail()
};
$.ajax({
url: "data.php",
method: "POST",
data: userData,
}).done(function(response) {
// finish function
}).fail(function(jqXHR, textStatus) {
// error function
});
}
$(文档).ready(函数(){
if(auth2.isSignedIn.get()){
var profile=auth2.currentUser.get().getBasicProfile();
用户数据={
id:profile.getId(),
名称:profile.getName(),
givenName:profile.getGivenName(),
familyName:profile.getFamilyName(),
imageUrl:profile.getImageUrl(),
电子邮件:profile.getEmail()
};
$.ajax({
url:“data.php”,
方法:“张贴”,
数据:userData,
}).完成(功能(响应){
控制台日志(响应);
}).fail(函数(jqXHR,textStatus){
console.log('error');
});
}
});代码>
此方法的警告是,您只验证用户的凭据客户端,而不验证令牌服务器端。这意味着有人可以向您的服务器端端点伪造姓名和电子邮件地址,并假装通过了google的身份验证
如果你的主要目的是使用谷歌服务,这可能没问题。如果不是这样,并且您希望使用Google验证用户的服务服务器端,则需要验证oauth服务器端。考虑使用谷歌来达到这个目的。
您可能面临的一个问题是,Google对您验证令牌的频率有API限制 编写一个ajax调用,将所有值发布到phpfile@NidhinChandran我不熟悉ajax。我只知道php。你能给我发一个演练或代码的链接吗?我对这个很陌生。所以请不要介意我问一个愚蠢的问题。但是我应该把这段代码放在标签之间吗?这是什么jquery库?检查jquery.com,我已经添加了一个代码片段,也检查了。我已经将url从data.php更改为我的页面,并且在我的php代码中还调用了$_POST['name']。没用。也许我做错了什么