Google Cloud Natural Language Example

181 Views Asked by At

I have followed the getting started page closely.

https://cloud.google.com/natural-language/docs/reference/libraries#client-libraries-install-php

The example code has the following: $projectId = 'YOUR_PROJECT_ID';

I fill in my project id taken from the json file and the Google console--e.g. "$projectID = 'myproject-197218'" and I always get a fatal error with "Permission Denied."

I have set the env variable, run composer to install the library. And, I created the Google json file. I am running the example in PHP code.

I am running the code on my local server (xampp).

2

There are 2 best solutions below

0
On

Are you sure that the ID of your project is that one? I'm working in Google Cloud and I cannot see this project ID in our database, but if I type "my-project-197218" with a "-" between "my" and "project" I am able to find one project. please, to make sure that this is your correct project ID, run this command in your Google Cloud Shell to get the default project ID:

gcloud config list --format 'value(core.project)' 2>/dev/null
0
On

I figured out my problem. The Google Cloud json file was stored on my drive d:, so in the env variable I referenced it as 'GOOGLE_APPLICATION_CREDENTIALS= d:\xampp\htdocs\googapi\mproj.json', it did not work; when I moved it to the root of the c: drive and referenced it there (GOOGLE_APPLICATION_CREDENTIALS=c:proj.json), it worked fine.