I am using this library: google/cloud-storage
.
In my storage I made a bucket, called: mycustombucket
. My goal is to upload a csv file in that bucket. Here is my code:
$storage = new StorageClient([
'projectId' => 'my project id',
'keyFile' => json_decode('{
"web":{
"client_id":"my client id",
"project_id":"my project id",
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url":"my auth value",
"client_secret":"my client secret"
}
}', true)
]);
$bucket = $storage->bucket('mycustombucket');
$bucket->upload(
fopen('path/to/my/file.csv', 'r')
);
Unfortunately, I got this error message: json key is missing the type field
. I found this similar POST , but it doesn't work for me. I think it is also outdated.
The content of the JSON, I downloaded it from here:
Would you please suggest me and idea, how to fix this?
Thank you!
In the end, I managed to get this work, by generating a key from the service account
. From:
Please not that once you generated you will automatically download it. A download button will not be available anymore. So make sure you have the key after generated it. I would expect to have a download button for the service account
, like I have for OAuth 2.0 Client IDs
(see my post). But I don't:(. Finally my code:
$storage = new StorageClient([
'projectId' => 'projectId' => 'my project id',
'keyFile' => json_decode('{
"type": "service_account",
"project_id": "my project id",
"private_key_id": "my key id",
"private_key": "my key",
"client_email": "email@email.com",
"client_id": "client id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "url here"
}', true)
]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.