How are you authorizing? Google's API requires OAuth authentication, the error you are receiving indicates you have not authorized.
Google gives the following to setup an account:
Step 1: Turn on the Google Sheets API
- Use this wizard to create or select a project in the Google Developers Console and automatically turn on the API. Click Continue, then Go to credentials.
- On the Add credentials to your project page, click the Cancel button.
- At the top of the page, select the OAuth consent screen tab. Select an Email address, enter a Product name if not already set, and click the Save button.
- Select the Credentials tab, click the Create credentials button and select OAuth client ID.
- Select the application type Other, enter the name "Google Sheets API Quickstart", and click the Create button.
- Click OK to dismiss the resulting dialog.
- Click the file_download (Download JSON) button to the right of the client ID.
- Move this file to your working directory and rename it
From that you should be able to get your key out of that JSON file. Then you need to authorize BEFORE you make an API request. Google has a guide for this as well:
Essentially, you need to:
-Send an authorization request with your key
-Use a successful authorization code to request a token
-Receive a token from the successful authorization
-Use the token to make an API request
This is not all done in one step, it is done with multiple steps. That second link above has HTTP/REST instructions for authenticating.
An auth request URL looks like this:
So if you run that through HTTP post, you should either get an error:
Or a success:
Then you take your auth code and do another POST action to request a token:
POST /oauth2/v4/token HTTP/1.1
If THAT is successful, you should receive a JSON response with a token:
Now that you have a token, you can finally make your API request using that access token:
Note at the bottom of that documentation it states:
Requires one of the following OAuth scopes:
This is not 101 stuff, so you may run into issues.
So much thanks for your help! The info is extremely helpful to me and I don't think I will ever figure this out on my own! (And likely keep pushing the post without a token)
I've just tested on the authentication process and yes I did ran into issues. But I guess after spending 6 hours today trying make this work definitely create some sort of temporary brain fatigue. Will try again tomorrow and keep you updated!
Super massive thanks!
Just break it down into smaller steps and do one thing at a time. “Rome wasn’t built in a day” and all of that.