This simple command-line application demonstrates how to invoke Google DLP API from PHP.
- Enable APIs - Enable the DLP API and create a new project or select an existing project.
- 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_CREDENTIALSto the path of the JSON key that was downloaded. - Clone the repo and cd into this directory
$ git clone https://github.com/GoogleCloudPlatform/php-docs-samples
$ cd php-docs-samples/dlp
- Install dependencies via Composer.
Run
php composer.phar install(if composer is installed locally) orcomposer install(if composer is installed globally). - 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/inspect_string.php Usage: php src/inspect_string.php PROJECT_ID STRING $ php src/inspect_string.php your-project-id 'bob@example.com' Findings: Quote: bob@example.com Info type: EMAIL_ADDRESS Likelihood: LIKELY
See the DLP Documentation for more information.
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 php7.3-bcmath
- See CONTRIBUTING.md
- See LICENSE
