Re: Expired token on newly created service account json keys

24 views
Skip to first unread message
Message has been deleted

Dylan Desrosiers

unread,
Apr 6, 2021, 1:48:19 PM4/6/21
to cloud-vision-discuss
I've had issues with doing it through an environment variable before. I'd recommend creating a new service account linked to your project, and downloading a new JSON keyfile. Put the keyfile somewhere in your repository (as long as it isn't public anywhere). Then, add the following to the top of you code:

<?php
// Authenticate with keyfile
$vision = new VisionClient([
'keyFile' => json_decode(file_get_contents('key/file/path/goes/here.json'), true)
]);
?>

This has worked for me. I used composer to install the GCP Vision API.

Let me know if that works for you. I just got this API up and running with PHP a few days ago so I should be able to help.

On Tuesday, April 6, 2021 at 12:40:50 PM UTC-4 Taras wrote:

Hello,

Trying to get this vision api working with php, i got it working 2 months ago but now it says token expired.
Followed the docs and created a service account and generated json keys, api is enabled, billing is enabled. Updated env variables and it doesn't let me get any response always says i'm unauthenticated and the token is expired for some reason even after trying with the old account and creating a new one, i'm using the same steps that worked for me earlier this year. Also tried with gcloud cli tool to auth but it doesn't work either.

Any advice ?
Thanks
Reply all
Reply to author
Forward
0 new messages