Hello I need to get access to a spreadsheet from google spreadsheet API. I have enabled Google Sheets API and added API key, but this doesn't work!!! https://sheets.googleapis.com/v4/spreadsheets/[my_spreadsheet_id]/values/A1?key=[my_api_key]
The result is: 403 - The caller does not have permission
But if I provide public access for this spreadsheet ---> it works!!!
The result is: 200 - [correct requested data .....]
The my question is: How to get access to a private spreadsheet from the API?
I need to read and write orders data there from my website using php's functions like file_get_contents()
To access the data stored in Google Sheets, you will need to create a service account and get a set of OAuth2 credentials from the Google API Console. Access the Google APIs Console while logged into your Google account. Create a new project and give it a name. Click on ENABLE APIS AND SERVICES .
Basically, you need to get authorization as mentioned in the documentation.
Whenever your application requests private user data, it must send an OAuth 2.0 token along with the request. Your application first sends a client ID and, possibly, a client secret to obtain a token. You can generate OAuth 2.0 credentials for web applications, service accounts, or installed applications.
Further information from OAuth 2.0 documentation, when accessing a Google API using OAuth 2.0, all applications follow these steps:
Before your application can access private data using a Google API, it must obtain an access token that grants access to that API.
Lastly, to help you with the implementation using PHP, you may also add Authentication and authorization to your list of references. Hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With