I wanted to use Google Cloud PHP Natural Language, so I added code from github to clone
https://github.com/googleapis/google-cloud-php-language
You have enabled and retrieved the API Key in advance.
The sample code in the github just now looks like this
use Google\Cloud\Language\LanguageClient;
$language = new LanguageClient();
// Analyze a presence.
$announcement=$language->annotateText('Greetings from Michigan!');
// Check the sentence.
if($announcement->sentiment()>0){
echo "This is a positive message.\n";
}
// Detect entities.
$entities=$announcement->entitiesByType('LOCATION');
foreach($entities as$entity){
echo$entity ['name']."\n";
}
// Parse the syntax.
$tokens=$notation->tokensByTag('NOUN');
foreach($token as $token){
echo$token['text']['content']."\n";
}
There is no part here to set the API key.
In fact, I still get an error when I try to access it.
{"error":{"code":403, "message":"The request is missing a valid API key.","status":"PERMISSION_DENIED"}
See to authenticate using the API key and it says to add it at the end of the URL.
POST https://language.googleapis.com/v1/documents:analyzeEntities?key=API_KEY
However, there is no item to set API_KEY in the above code.
Or you can use the x-goog-api-key header to pass the key...
How can I set the API key?
Thank you for your cooperation.
I received similar questions and answers below.
See also
If you know keyFilePath, why don't you try it?
$language=new LanguageClient([]
'projectId' = > 'my-project-id',
'keyFilePath' = > '/path/to/my/keyfile.json'
]);
628 GDB gets version error when attempting to debug with the Presense SDK (IDE)
639 Uncaught (inpromise) Error on Electron: An object could not be cloned
563 Unable to install versioned in Google Colab
933 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.