Request had invalid authentication credentials. Expected OAuth 2 access token error

3.9k Views Asked by At

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?

1

There are 1 best solutions below

1
Linda Lawton - DaImTo On
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.