简体   繁体   English

从谷歌登录获取用户名和电子邮件

[英]Getting user name and email from Google Login

I am honestly confused.老实说,我很困惑。 This is for a commercial product and my app permissions list their name and email as part of the google sign in. My users very much want to give me their name and email, I am just adding Google Login to make it easier for them to do so per user request.这是针对商业产品的,我的应用程序权限将他们的姓名和电子邮件列为谷歌登录的一部分。我的用户非常想给我他们的姓名和电子邮件,我只是添加谷歌登录,让他们更容易做到所以根据用户要求。

My code is just from here: https://developers.google.com/+/web/people/ .我的代码来自这里: https ://developers.google.com/+/web/people/。

I am trying to let users login to my site with Google and to then read their name and email to store in my account database.我试图让用户使用 Google 登录我的网站,然后读取他们的姓名和电子邮件以存储在我的帐户数据库中。

Currently the login is working correctly (I can log in and am writing my login token, client_id etc to the console) but when I try and request the email/name I get an error:目前登录工作正常(我可以登录并将我的登录令牌、client_id 等写入控制台)但是当我尝试请求电子邮件/名称时出现错误:

Daily Limit for Unauthenticated Use Exceeded.超出未经身份验证使用的每日限制。 Continued use requires signup.继续使用需要注册。

I have created an app here https://console.developers.google.com , got my client_id set the allowed origin, etc and I set a logo and such that I see when I click the sign in button so I believe it is correctly identifying my account when the sign in button is clicked.我在这里创建了一个应用程序https://console.developers.google.com ,让我的 client_id 设置了允许的来源等,我设置了一个标志,当我点击登录按钮时我会看到,所以我相信它是正确的单击登录按钮时识别我的帐户。

My code to request the user profile data is below我请求用户个人资料数据的代码如下

function _onGoogleLogin(){
  gapi.client.load('plus', 'v1', function(){
    gapi.client.plus.people.get({userId: 'me'}).execute(handleGoogleUserDataResponse);        
  });                                                                                         
  function handleGoogleUserDataResponse(resp) {                                               
    console.log("google user data", resp);                                                    
  }
}

Do I need a paid account on the Google Developer platform to access this information more than once or twice a day?我是否需要 Google Developer 平台上的付费帐户才能每天多次访问此信息? That seems insane.这看起来很疯狂。 I am using Facebook login already and with FB the process was trivially simple and free.我已经在使用 Facebook 登录,并且使用 FB,这个过程非常简单而且免费。

I assume I am doing something stupid wrong.我假设我做错了愚蠢的事情。 Do I need to separately give my client_id to gapi or something?我是否需要单独将我的 client_id 提供给 gapi 或其他东西? Currently I just have this for the signin button per their documentation.目前,根据他们的文档,我只有这个用于登录按钮。

<meta name="google-signin-clientid" content="CLIENT_ID" />

Any help would be appreciated, thanks!任何帮助将不胜感激,谢谢!

You did not follow all the steps in the document.您没有遵循文档中的所有步骤。

When you make an API call, you need to have the proper Client-ID setup so Google can track which Application is making which call.当您进行 API 调用时,您需要设置正确的客户端 ID,以便 Google 可以跟踪哪个应用程序正在进行哪个调用。 It's used for authentication as well as usage tracking.它用于身份验证和使用跟踪。 You get free test API calls but if you want to make REAL use of the API, you must follow the document and set everything up.您可以获得免费的测试 API 调用,但如果您想真正使用 API,则必须遵循文档并设置所有内容。

You DO NOT need to enable billing as long as you use minimum amount of API calls, there's a daily free quota.只要您使用最少数量的 API 调用,您就不需要启用计费,每天有一个免费配额。

===---=== ===---===

If you have the proper Client-ID setup but the API calls are still using unauthenticated credentials, then try an incognito browser.如果您有正确的客户端 ID 设置,但 API 调用仍在使用未经身份验证的凭据,请尝试使用隐身浏览器。 Chrome sometimes does weird things when it comes to multi-profiles.当涉及到多配置文件时,Chrome 有时会做一些奇怪的事情。

The issue is that users are being signed out immediately.问题是用户被立即注销。 This is due to a known bug in the google login system, more details are here:这是由于谷歌登录系统中的一个已知错误,更多细节在这里:

G+ Login Immediately Logs Me out 3x Using g-signin Button G+ 登录立即使用 g-signin 按钮将我注销 3 倍

This is exactly the behavior I am encountering.这正是我遇到的行为。

From the response, you get the credential and then you have to decode it from jwt_decode(npm).like this var decoded = jwt_decode(res.credential);从响应中,您获得了凭据,然后您必须从 jwt_decode(npm) 对其进行解码。就像这样 var decoded = jwt_decode(res.credential); Then you get an object through which you can access email, picture and name.然后你会得到一个对象,通过它你可以访问电子邮件、图片和姓名。 and then store it in storage and parse it to use.然后将其存储在存储中并解析它以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从 firebase 登录谷歌帐户 - Can't login into google account from firebase Firebase Android - 如何以不同用户身份登录(使用 Google 登录后) - Firebase Android - how to login as different user (after signing in with Google) Firebase Auth - 没有来自谷歌登录提供商的电子邮件 - Firebase Auth - no email from google sign in provider 如何设置索引以便用户可以在 Dynamodb 中通过电子邮件或用户名登录 - How to set up indexes so a user can login via email or username in Dynamodb 尝试推送到 git 实验室时,“确保在 git 中配置了 'user.email' 和 'user.name'” - "Make sure you configure your 'user.email' and 'user.name' in git" when trying to push to git lab 管理员和用户从反应和后端的同一登录页面登录我正在使用 firebase - Admin and user login from same login page in react and back end i am using firebase 从 android 到 Google 应用引擎 - getting from android to Google app engine 如何在 Firebase 身份验证上区分电子邮件验证用户和非验证用户? - How to distinguish email-verified user from non-verified user on Firebase Authentication? 重定向页面登录谷歌 - Redirect Page Login google 发送电子邮件到当前用户电子邮件 - send email to current user email in flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM