Answer the question
In order to leave comments, you need to log in
Google api where to get token.json and credentials.json?
To connect to the google docs api, I use the following code, which I took from the examples in the documentation.
It requires two files, credentials.json and token.json.
Where can I get them? Or if you create yourself what should be in them?
$client = new Google_Client();
$client->setApplicationName('Google Sheets API PHP Quickstart');
$client->setScopes(Google_Service_Sheets::SPREADSHEETS_READONLY);
$client->setAuthConfig( 'credentials.json');
$client->setAccessType('offline');
// Load previously authorized credentials from a file.
$credentialsPath = 'token.json';
if (file_exists($credentialsPath)) {
$accessToken = json_decode(file_get_contents($credentialsPath), true);
}
Answer the question
In order to leave comments, you need to log in
November 2021
How I did it with Golang and quickstart from Google (link to this quickstart - https://developers.google.com/sheets/api/quickstart/go ).
This is not the case for other languages, but it probably works in such a way that you need client_secret.json (it seems to be the same as credentials.json, but not 100% sure) and token.json idea is somehow generated from client_secret.json.
client_secret.json can be obtained using https://console.cloud.google.com/apis/credentials . (click "CREATE CREDENTIALS" -> "OAuth client ID" -> "select application type and token name" -> "Click the Download button")
I am writing this answer so that people have at least some additional opportunity to understand what can be done and how, and not "do the same, even if you are programming in C++/C#/Python/etc"
1. Go to https: //console.cloud.google.com/apis/credentials
2. Click "CREATE CREDENTIALS"
3. Select "OAuth client ID"
4. Select the required option in "Application type" and so on. I don't know what exactly it means.
5. Download client_secret.json file (same credentials.json as far as I understand)
6. Add client_secret.json to go QuickStart
7. Launch QuickStart. The running program in the console will ask you to follow the link (the program will give the link in the same place, in the console) and paste the code into the console (you will see the code when you follow the link)
8. The program will generate token.json
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question