Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

Outline

Google Service Directory PHP Sample Application

Open in Cloud Shell

Description

This simple command-line application demonstrates how to invoke the Google Service Directory API from PHP.

Build and Run

  1. Enable APIs - Enable the Service Directory API and create a new project or select an existing project.
  2. Download The Credentials - Click "Go to credentials" after enabling the APIs. Click "New Credentials" and select "Service Account Key". Create a new service account, use the JSON key type, and select "Create". Once downloaded, set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON key that was downloaded.
  3. Clone the repo and cd into this directory
    $ git clone https://github.com/GoogleCloudPlatform/php-docs-samples
    $ cd php-docs-samples/servicedirectory
  1. Install dependencies via Composer. Run php composer.phar install (if composer is installed locally) or composer install (if composer is installed globally).
  2. Execute the snippets in the src/ directory by running php src/SNIPPET_NAME.php. The usage will print for each if no arguments are provided:
    $ php src/quickstart.php
    Usage: php src/quickstart.php PROJECT_ID STRING
    
    $ php src/quickstart.php your-project-id us-east1
    Namespaces: projects/you-project-id/locations/us-east1/namespaces/your-namespace

See the Service Directory Documentation for more information.

Troubleshooting

bcmath extension missing

If you see an error like this:

PHP Fatal error:  Uncaught Error: Call to undefined function Google\Protobuf\Internal\bccomp() in /usr/local/google/home/crwilson/github/GoogleCloudPlatform/php-docs-samples/dlp/vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php:986

You may need to install the bcmath PHP extension. e.g. (may depend on your php version)

$ sudo apt-get install php8.1-bcmath

Contributing changes

Licensing

Morty Proxy This is a proxified and sanitized view of the page, visit original site.