0

I am using PHP library for using Google Cloud Vision. The docs tells about 2 ways of authentication - 1) API and 2) Service Account.

How do I use API based auth with my VisionClient? There is no document on using it. Please let me know if I am wrong.

    $vision = new VisionClient([
        'projectId' => 'ophoto'
    ]);

    $image = $vision->image($photoResource, 
             ['LABEL_DETECTION','SAFE_SEARCH_DETECTION','IMAGE_PROPERTIES']);

    $vision->annotate($image);

I get the below error message when running the above code.

Message:    Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information
File:   C:\Program Files\VertrigoServ\www\classes\vendor\google\cloud\src\RequestWrapper.php
Line:   219
Trace:  
#0 C:\Program Files\VertrigoServ\www\classes\vendor\google\cloud\src\RequestWrapper.php(185): Google\Cloud\RequestWrapper->convertToGoogleException(Object(DomainException))
#1 C:\Program Files\VertrigoServ\www\classes\vendor\google\cloud\src\RequestWrapper.php(167): Google\Cloud\RequestWrapper->fetchCredentials()
#2 C:\Program Files\VertrigoServ\www\classes\vendor\google\cloud\src\RequestWrapper.php(150): Google\Cloud\RequestWrapper->getToken()
#3 C:\Program Files\VertrigoServ\www\classes\vendor\google\cloud\src\RequestWrapper.php(131): Google\Cloud\RequestWrapper->signRequest(Object(GuzzleHttp\Psr7\Request))
#4 C:\Program Files\VertrigoServ\www\classes\vendor\google\cloud\src\RestTrait.php(80): Google\Cloud\RequestWrapper->send(Object(GuzzleHttp\Psr7\Request), Array)
#5 C:\Program Files\VertrigoServ\www\classes\vendor\google\cloud\src\Vision\Connection\Rest.php(57): Google\Cloud\Vision\Connection\Rest->send('images', 'annotate', Array)
#6 C:\Program Files\VertrigoServ\www\classes\vendor\google\cloud\src\Vision\VisionClient.php(265): Google\Cloud\Vision\Connection\Rest->annotate(Array)
#7 C:\Program Files\VertrigoServ\www\bol\service.php(60): Google\Cloud\Vision\VisionClient->annotateBatch(Array)
#8 C:\Program Files\VertrigoServ\www\init.php(34): PHOTOTAGS_BOL_Service->analyzeImages(Array)
#9 [internal function]: phototags_user_register(Object(OW_Event))
#10 C:\Program Files\VertrigoServ\www\oxwall\ow_core\event_manager.php(228): call_user_func('phototags_user_...', Object(OW_Event))
#11 C:\Program Files\VertrigoServ\www\oxwall\ow_plugins\photo\controllers\ajax_upload.php(263): OW_EventManager->trigger(Object(OW_Event))
#12 C:\Program Files\VertrigoServ\www\oxwall\ow_plugins\photo\controllers\ajax_upload.php(227): PHOTO_CTRL_AjaxUpload->onSubmitComplete('user', 1, Object(PHOTO_BOL_PhotoAlbum), Array)
#13 [internal function]: PHOTO_CTRL_AjaxUpload->ajaxSubmitPhotos(Array)
#14 C:\Program Files\VertrigoServ\www\oxwall\ow_core\request_handler.php(250): ReflectionMethod->invokeArgs(Object(PHOTO_CTRL_AjaxUpload), Array)
#15 C:\Program Files\VertrigoServ\www\oxwall\ow_core\request_handler.php(226): OW_RequestHandler->processControllerAction(Object(ReflectionMethod), Object(PHOTO_CTRL_AjaxUpload))
#16 C:\Program Files\VertrigoServ\www\oxwall\ow_core\application.php(346): OW_RequestHandler->dispatch()
#17 C:\Program Files\VertrigoServ\www\oxwall\index.php(76): OW_Application->handleRequest()
#18 {main}
Type:   Google\Cloud\Exception\ServiceException
Purus
  • 5,701
  • 9
  • 50
  • 89

2 Answers2

0

Please, find here a several example to use Cloud Vision API with PHP Language!

I hope can it help you!

Osoter
  • 571
  • 3
  • 9
  • Sorry. It does not. It says only about using service account and not using API keys. – Purus Feb 25 '17 at 12:30
  • Can this be helpful for you? https://developers.google.com/identity/protocols/application-default-credentials https://cloud.google.com/vision/docs/reference/libraries#client-libraries-install-php http://terrenceryan.com/blog/index.php/working-with-cloud-vision-api-from-php/ – Osoter Feb 27 '17 at 10:36
0

In case you plan to continue running it locally, you can authenticate by running gcloud auth application-default login command and then use the Cloud Vision API Client Libraries to run your service. See this Using the client library section for additional details.

Alex
  • 315
  • 5
  • 17