3
votes

I want to use Google Cloud Vision API on a family photo. I activated the API on my GCP account, received an API Key but I don't know where I should insert it. Here's my code :

<?
require 'vendor/autoload.php';
use Google\Cloud\Vision\VisionClient;
$vision = new VisionClient();
$image = $vision->image(
    fopen('data/family_photo.jpg', 'r'),
    ['faces']
);
$annotation = $vision->annotate($image);
var_dump($annotation);
die();

?>

I get the following error : "error": { "code": 403, "message": "The request is missing a valid API key.", "status": "PERMISSION_DENIED" } }.

Update: Thanks to the provided answer by Dan D., I added the following line:

putenv("GOOGLE_APPLICATION_CREDENTIALS=book.json");
1

1 Answers

4
votes

I think that for using the Google Cloud PHP SDK you need to use a Service Account. As stated here (https://github.com/googleapis/google-cloud-php/blob/master/AUTHENTICATION.md), you will need to have an environment variable setup that points to the JSON file with the credentials.

$ export GOOGLE_APPLICATION_CREDENTIALS=<path_to_service_account_file>

Also you can follow this guide (https://cloud.google.com/video-intelligence/docs/common/auth) to create Service Account and generate the JSON file. Hope this helps.