PHP code example of webmarketer / webmarketer-php

1. Go to this page and download the library: Download webmarketer/webmarketer-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webmarketer / webmarketer-php example snippets


try {
    // create an instance of the SDK with the desired configuration
    $client = new \Webmarketer\WebmarketerSdk([
        'default_project_id' => 'webmarketer-awesome-project'
    ]);
} catch (\Webmarketer\Exception\DependencyException $dep_ex) {
    // SDK init throw a dependency exception if >getEventTypeService();
$field_service = $client->getFieldService();

try {
    $sa_auth_provider = new \Webmarketer\Auth\ServiceAccountAuthProvider([
       // stringified service account
       'credential' => '{ ...serviceAccount }',
       // desired scopes, space separated
       'scopes' => 'full_access'
    ]);
    // create an instance of the SDK with the custom auth provider
    $client = new \Webmarketer\WebmarketerSdk(
        [
            'default_project_id' => 'webmarketer-awesome-project'
        ],
        $sa_auth_provider
    );
} catch (\Webmarketer\Exception\DependencyException $dep_ex) {
    // SDK init throw a dependency exception if 

try {
    $refresh_token_auth_provider = new \Webmarketer\Auth\RefreshTokenAuthProvider([
       // oauth application client_id
       'client_id' => 'appclientid',
       // oauth application client_secret
       'client_secret' => 'appclientsecret',
       // refresh token
       'refresh_token' => 'myrefreshtoken'
    ]);
    // create an instance of the SDK with the custom auth provider (this time the refresh_token_auth_provider)
    $client = new \Webmarketer\WebmarketerSdk(
        [
            'default_project_id' => 'webmarketer-awesome-project'
        ],
        $refresh_token_auth_provider
    );
    // perform an exchange of the refresh flow to get an access token as well as a new refresh token
    $response = $client->getAuthProvider()->refreshToken();
    // new refresh token can be securely stored for future use
    $new_refresh_token = $response['refresh_token'];
} catch (\Webmarketer\Exception\DependencyException $dep_ex) {
    // SDK init throw a dependency exception if 
bash
composer