Asked by:
How to do google signin (People API)

Question
-
User944339287 posted
Hi guys.. i wonder how to implement google signin by using People API?
Firstly, I can get profile data in API Explorer at https://developers.google.com/people/api/rest/v1/people/get
I wanna implement google sign-in in my web application now, but i can only get Client ID & Secret Key from https://console.developers.google.com/
how can i get API Key for People API?
Below is my code to get profile data in my web application:Dim wc As WebClient = New WebClient With { .Encoding = Encoding.UTF8 } Dim client_id As String = "" Dim client_secret_key As String = "" Dim key As String = "XXXXXXXXXXXXXXXXXXXX" Try Dim jsonstring As String = wc.DownloadString("https://people.googleapis.com/v1/people/me?personFields=names&key=" & key & "") Dim jobj As JObject = CType(JsonConvert.DeserializeObject(jsonstring), JObject) For Each entry In jobj("items") Response.Write(entry("emailAddresses")("value").ToString()) Next Catch ex As Exception Response.Write(ex.Message) End Try
Monday, March 9, 2020 7:37 AM
All replies
-
User753101303 posted
Hi,
You are using ASP.NET 4.x or ASP.NET Core?
I would suggest to first try https://docs.microsoft.com/en-us/aspnet/mvc/overview/security/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on or https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins?view=aspnetcore-3.1 if not done already.
Monday, March 9, 2020 10:54 AM -
User944339287 posted
Hi, i am using .Net Framework 4.0Monday, March 9, 2020 11:26 AM -
User753101303 posted
I never remember if 4.0 is enough or if you have to use 4.5 or later (note that the oldest supoort .NET version is 4.5.2).
Do you want to try https://docs.microsoft.com/en-us/aspnet/mvc/overview/security/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on or to integrate that yourself by usin g directly the people api ?
I'm not sure you need an API key (and the link above doesn't) as you'll access to the currently logged in user.
Edit: according to https://developers.google.com/people/v1/how-tos/authorizing :
"A request that does not provide an OAuth 2.0 token must send an API key" so it seems to imply that if using OAuth you don't have to send an API key.
Monday, March 9, 2020 2:01 PM -
User-719153870 posted
Hi kengkit,
how can i get API Key for People API?Check the Google People Api doc Acquiring and using an API key:
To acquire an API key:
- Open the Credentials page in the API Console.
- Go to "Credentials" - "Create Credentials" - "API key"
Best Regard,
Yang Shen
Tuesday, March 10, 2020 4:54 AM -
User944339287 posted
Thank! I have got my API key.
I wondering why i will get this error message while i trying to implement google login
The remote server returned an error: (401) Unauthorized.
Is it because of my Verification Status: Being verified in OAuth consent screen?
Below is my code for implement google login.Dim wc As WebClient = New WebClient With { .Encoding = Encoding.UTF8 } Dim key As String = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" Try Dim jsonstring As String = wc.DownloadString("https://people.googleapis.com/v1/people/me?personFields=names%2Cbirthdays%2CcoverPhotos%2CemailAddresses%2Cgenders&key=" & key & "") Dim jobj As JObject = CType(JsonConvert.DeserializeObject(jsonstring), JObject) For Each entry In jobj("items") Response.Write(entry("emailAddresses")("value").ToString()) Next Catch ex As Exception Response.Write(ex.Message) End Try
Tuesday, March 10, 2020 9:50 AM -
User475983607 posted
Your approach is not OAuth. The user secret is used to identify your application and get an access token. You write code to add the bearer token to the HTTP header.
https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions/using-oauth-providers-with-mvc
Tuesday, March 10, 2020 10:29 AM