How to connect to Google APIs

Posted on

I had small issue searching for the right way connecting to Google Cloud APIs, that’s why I want to show you how to connect with an example for Vision API, you can find that the steps are easy but I will list them.

  • Create Google account and API key in
  • Enable Google Cloud Vision API or any other that you need
  • Create Service account key
    • You will receive JSON file which has to be stored somewhere in the project
    • Set the path to this JSON in global environment variable, with PHP is like this
      putenv('GOOGLE_APPLICATION_CREDENTIALS=' . realpath('./path-to-the-JSON-file.json'));
  • Run composer require google/cloud to download Google APIs
  • Then in your PHP file you can do use Google\Cloud\Vision\VisionClient or the API that you need
  • Creating instance of the API
     $vision = new VisionClient(
                    'projectId' => 'YOUR-API-KEY',

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.