2

I need to read and import google people contacts but I get the following error:

"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project." "status": "UNAUTHENTICATED"

This is the script (classic asp) I am using:

StrURL="https://people.googleapis.com/v1/people/get"

ApiKey="my api key"

Set objXMLHTTP = CreateObject("Msxml2.ServerXMLHTTP.6.0")

objXMLHTTP.Open "GET", StrURL, False

On Error Resume Next

objXMLHTTP.setRequestHeader "Authorization", "Bearer " & ApiKey

If Err.Number<>0 Then Response.Write "Error:" & Err.Description & "<br>"

On Error GoTo 0

objXMLHTTP.send

content = CStr(objXMLHTTP.ResponseText)

statuscode = objXMLHTTP.Status

How can I get the token using classic asp? Can anyone help me?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Pablo
  • 21
  • 1
  • 2

1 Answers1

2
objXMLHTTP.setRequestHeader "Authorization", "Bearer " & ApiKey

You appear to be sending an api key. An api key is not a bearer token. Api keys only grant you access to public data, not private user data.

In order to access private user data you need to request authorization from that user to access that data that is done using Oauth2

Once you have been grated consent of the user to access their data you will have an access token. This access token can then be sent to the api in the authorization header.

I haven't used asp classic in years. These videos may help you understand how to make the authorization request.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • 3
    thanks ... you saved my life !!! In the first link you sent me it helped me understand how to generate the oauth token and then use it to query google api. – Pablo Aug 25 '22 at 11:03