PHP code example of gozfly / gozfly-api-php-client

1. Go to this page and download the library: Download gozfly/gozfly-api-php-client 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/ */

    

gozfly / gozfly-api-php-client example snippets


// ... please, add composer autoloader first
// instantiate the Gozfly client
$client = new Client(
    'GOZFLY_APP_CLIENT_ID',  
    'GOZFLY_APP_CLIENT_SECRET'
);

$redirectUrl = $client->getRedirectUrl();

$client->setRedirectUrl('http://your.domain.tld/path/to/script/');

use Gozfly\Scope;

// define scope
$scopes = [
  Scope::READ_BASIC_PROFILE, 
  Scope::READ_EMAIL_ADDRESS,
  Scope::MANAGE_COMPANY,
  Scope::SHARING,
];
$loginUrl = $client->getLoginUrl($scopes); // get url on Gozfly to start linking

$accessToken = $client->getAccessToken($_GET['code']);

file_put_contents('token.json', json_encode($accessToken));

use Gozfly\AccessToken;
use Gozfly\Client;

// instantiate the Gozfly client
$client = new Client(
    'GOZFLY_APP_CLIENT_ID',  
    'GOZFLY_APP_CLIENT_SECRET'
);

// load token from the file
$tokenString = file_get_contents('token.json');
$tokenData = json_decode($tokenString, true);
// instantiate access token object from stored data
$accessToken = new AccessToken($tokenData['token'], $tokenData['expiresAt']);

// set token for client
$client->setAccessToken($accessToken);

$profile = $client->api(
    'ENDPOINT',
    ['parameter name' => 'its value here'],
    'HTTP method like GET for example'
);

// get method
$client->get('ENDPOINT', ['param' => 'value']);

//post
$client->post('ENDPOINT', ['param' => 'value']);

$profile = $client->get(
    'people/~:(id,email-address,first-name,last-name)'
);
print_r($profile);

$profile = $client->get(
    'companies',
    ['is-company-admin' => true]
);
print_r($profile);

$share = $client->post(
    'people/~/shares',
    [
        'comment' => 'Checkout this amazing PHP SDK for Gozfly!',
        'content' => [
            'title' => 'PHP Client for Gozfly API',
            'description' => 'OAuth 2 flow, composer Package',
            'submitted-url' => 'https://www.github.com/gozfly/gozfly-api-php-client',
            'submitted-image-url' => 'https://www.github.com/fluidicon.png',
        ],
        'visibility' => [
            'code' => 'anyone'
        ]
    ]
);

// set sandboxed company page to work with
// you can check updates at
// https://www.gozfly.com/company/devtestco
$companyId = '2414183';

$share = $client->post(
    'companies/' . $companyId . '/shares',
    [
        'comment' => 'Checkout this amazing PHP SDK for Gozfly!',
        'content' => [
            'title' => 'PHP Client for Gozfly API',
            'description' => 'OAuth 2 flow, composer Package',
            'submitted-url' => 'https://www.github.com/gozfly/gozfly-api-php-client',
            'submitted-image-url' => 'https://www.github.com/fluidicon.png',
        ],
        'visibility' => [
            'code' => 'anyone'
        ]
    ]
);

$client->setDefaultApiHeaders([
  'Content-Type' => 'application/json',
  'x-li-format' => 'json',
  'x-li-src' => 'msdk' // set a src header to "msdk" to mimic a mobile SDK
]);

$client->setApiRoot('https://api.gozfly.com/v2/');