I've downloaded my client_secret.json by going to URL https://console.developers.google.com/apis/credentials and clicking the 'Download JSON' option. Downloaded the JSON successfully, pasted below;
{
"installed": {
"client_id": "dummyID",
"project_id": "dummy-id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs"
}
}
And my calling code;
$client = new \Google_Client();
putenv('GOOGLE_APPLICATION_CREDENTIALS='.CONFIG.'client_secret.json');
$client->useApplicationDefaultCredentials();
$client->setSubject('[email protected]');
$client->addScope('https://www.googleapis.com/auth/drive.file');
$service = new \Google_Service_Drive($client);
$file = new \Google_Service_Drive_DriveFile($client);
$result = $service->files->create($file, array( // Error here
'data' => file_get_contents(SHEETS.'review.xlsx'),
'mimeType' => 'application/vnd.google-apps.spreadsheet',
'uploadType' => 'media'
));
This code gives me the exception
json key is missing the type field
The only reference I can find for this is here
https://github.com/google/google-auth-library-php/blob/master/src/CredentialsLoader.php#L129
Could someone tell me why I am getting this error please? It's looking for type field in my client_secret.json but I'm not sure why?
Thanks in advance.
Same problem here.
I tried to use:
$client->setAuthConfig('client_secret.json');
But then I got these notices (and it isn't working either):
PHP Notice: Undefined index: client_secret in google-api-php-client/vendor/google/apiclient/src/Google/Client.php on line 862
Notice: Undefined index: client_secret in google-api-php-client/vendor/google/apiclient/src/Google/Client.php on line 862
@xorexore It turns out I was downloading the wrong client secret. You have to download the client secret for the service not the client account.
I want to get the drive's spreadsheets list. I am using the Drive api. while running apitest.php file. I face the error:
PHP Fatal error: Uncaught InvalidArgumentException: json key is missing the typ
e field in C:\xampp\htdocs\googleSheets\vendor\google\auth\src\CredentialsLoader
.php:129
Stack trace:
: Google\Auth\CredentialsLoader::makeCredentials('https://www.goo...', Object(Gu
zzleHttp\Psr7\Stream))
ials.php(137): Google\Auth\CredentialsLoader::fromEnv('https://www.goo...')
54): Google\Auth\ApplicationDefaultCredentials::getCredentials('https://www.goo.
..')
6): Google_Client->createApplicationDefaultCredentials()
WithAssertion()
thrown in C:\xampp\htdocs\googleSheets\vendor\google\auth\src\CredentialsLoade
r.php on line 129
Fatal error: Uncaught InvalidArgumentException: json key is missing the type fie
ld in C:\xampp\htdocs\googleSheets\vendor\google\auth\src\CredentialsLoader.php:
129
Stack trace:
: Google\Auth\CredentialsLoader::makeCredentials('https://www.goo...', Object(Gu
zzleHttp\Psr7\Stream))
ials.php(137): Google\Auth\CredentialsLoader::fromEnv('https://www.goo...')
54): Google\Auth\ApplicationDefaultCredentials::getCredentials('https://www.goo.
..')
6): Google_Client->createApplicationDefaultCredentials()
WithAssertion()
thrown in C:\xampp\htdocs\googleSheets\vendor\google\auth\src\CredentialsLoade
r.php on line 129
@Sharma-Ravin You have probably downloaded the wrong kind of credentials. Try downloading a new set of client credentials.
from where to download to download the client secret for the service ?
Download them from https://console.cloud.google.com/apis/credentials
@xorexore It turns out I was downloading the wrong client secret. You have to download the client secret for the service not the client account.
I'm having the same error here, but I don't understand this answer. I only have one download link on the Credentials section, and that is to the right, under the heading of "OAuth 2.0 client IDs". I downloaded the only file I could on the page as a JSON file, but still get the same error.
This worked for me, on the Account Services page I click on Furnish a new private key, this key will generate a JSON file that will contain the type field. You can check the steps here
Most helpful comment
@xorexore It turns out I was downloading the wrong client secret. You have to download the client secret for the service not the client account.