获取“gapi.client 未定义"尝试检索经过身份验证的 Google+ 用户的电子邮件地址时 [英] Getting "gapi.client is undefined" when trying to retrieve an authenticated Google+ user's email address
问题描述
我正在尝试从使用 google + 登录按钮登录到我的网站的访问者那里检索用户数据,但我最终在 javascript 控制台中收到消息TypeError: gapi.client is undefined".
I'm trying to retrieve user data from a visitor who has signed in to my site using google + sign in button, but I just end up with the message "TypeError: gapi.client is undefined" in the javascript console.
由于我无法识别错误,我最终从 Google 复制/粘贴了示例代码,可在此处找到:https://developers.google.com/+/web/people/#retrieve_an_authenticated_users_email_address
Since I could not identify the error I finally copy/pasted the example code from Google, which can be found here: https://developers.google.com/+/web/people/#retrieve_an_authenticated_users_email_address
我唯一改变的是客户端 ID(对于 Web 应用程序).
The only thing I changed was the Client ID (for web applications).
我仍然遇到同样的错误!
And I STILL get the same error!
由于示例代码对我不起作用,我在想,也许我在 Google API 控制台中的设置是错误的.我已尝试按照说明操作:
Since the example code does not work for me, I'm thinking, maybe my settings in the Google API Console are wrong. I have tried to follow the instructions:
- Google+ API 服务已启用
- 重定向 URI:无
- JavaScript origins 设置为 localhost 和实际生产域.
也尝试将示例代码上传到生产服务器,只是为了看看这是不是本地环境问题,但我仍然遇到相同的错误.
Have also tried to upload the example code to the production server, just to see if this was a local environment issue, but I still get the same error.
推荐答案
除了 plusone
脚本外,您还必须包含脚本和 client
API:>
You must include the script and include the client
API in addition to the plusone
script:
<script src="https://apis.google.com/js/client:plusone.js" type="application/javascript"></script>
演示页面做错了,我已经修复了.
The demo page was doing it incorrectly, which I've fixed.
这篇关于获取“gapi.client 未定义"尝试检索经过身份验证的 Google+ 用户的电子邮件地址时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!