Javascript 谷歌和他的API或登录按钮有困难
我遵循了他们的文档,我看不出我的部分有什么错误 我试图从用户的个人资料中获取信息(可能是姓名、性别等) 我遵循了google网站的所有步骤(在我的例子中是javascript代码) 一切都正常,少了我想对用户配置文件执行的请求 此示例是登录到google帐户后自动执行的回调函数:Javascript 谷歌和他的API或登录按钮有困难,javascript,google-plus,google-login,Javascript,Google Plus,Google Login,我遵循了他们的文档,我看不出我的部分有什么错误 我试图从用户的个人资料中获取信息(可能是姓名、性别等) 我遵循了google网站的所有步骤(在我的例子中是javascript代码) 一切都正常,少了我想对用户配置文件执行的请求 此示例是登录到google帐户后自动执行的回调函数: function signinCallback(authResult) { if (authResult['status']['signed_in']) { // Update the app to ref
function signinCallback(authResult) {
if (authResult['status']['signed_in']) {
// Update the app to reflect a signed in user
// Hide the sign-in button now that the user is authorized, for example:
//document.getElementById('signinButton').setAttribute('style', 'display: none');
console.log(authResult);
gapi.client.setApiKey('API_KEY'); //(That function gaves me an error which is invalid credentials, i did put my API_KEY (from the google console ))
gapi.client.load('plus','v1', function(){
var request = gapi.client.plus.people.get({
'userId': 'me'
});
request.execute(function(resp) {
console.log(resp);
//console.log('Retrieved profile for:' + resp.displayName);
});
});
gapi.auth.signOut(); // logging out !
} else {
// Update the app to reflect a signed out user
// Possible error values:
// "user_signed_out" - User is signed-out
// "access_denied" - User denied access to your app
// "immediate_failed" - Could not automatically log in the user
console.log('Sign-in state: ' + authResult['error']);
}
}
一切都不如设置键和下面的一切有效!
如果我没有将set函数和代码放在下面,我会收到一个400错误(“消息”:“超出未经验证使用的每日限制。继续使用需要注册。”)
所以我真的对这样做失去了希望。。。我认为谷歌的文档太糟糕了!
怎么了
祝大家圣诞快乐
旁白:是的,我知道API密钥musn不是硬编码的,但我对来自谷歌的文档非常迷茫…可能的解决方案:
尝试删除
gapi.client.setApiKey('API_KEY')代码>
及
gapi.auth.signOut();//注销代码>
signOut工作得非常快,而gapi.client.load
是加载js代码的异步函数。用户可能在执行gapi.client.load
回调之前注销
我不确定是否需要:
转到Google开发者控制台
选择您的项目
在左侧的侧栏中,选择API&auth
在显示的API列表中,找到Google+API并将其状态设置为ON
请确保您正在请求作用域或登录。如果您正在以用户身份进行身份验证的请求,则无需设置API密钥。Reallyyy????就因为图章工作得很快?来一个:(那setApiKey呢?它有什么用?谢谢,它现在可以用了!)