PHP code example of playerlync / playerlync-sdk-php

1. Go to this page and download the library: Download playerlync/playerlync-sdk-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/ */

    

playerlync / playerlync-sdk-php example snippets




define('PLAYERLYNC_SDK_PHP_SRC_DIR', '/path/to/playerlync-sdk-php/src/PlayerLync/');

$playerlync = new \PlayerLync\PlayerLync([
        'host' => '{host}',
        'client_id' => '{client-id}',
        'client_secret' => '{client-secret}',
        'username' => '{username}',
        'password' => '{password}',
    ]);

try
{
  $playerlync = new \PlayerLync\PlayerLync([/*.....*/]);

  $response = $playerlync->get('/members', ['limit'=>50]);
  $members = $response->getData();

  echo 'API returned '. count($members) . ' members!';
}
catch(PlayerLync\Exceptions\PlayerLyncResponseException $e)
{
  // When PlayerLync API returns an error
  echo 'PlayerLync API returned an error: ' . $e->getMessage();
  exit;
}
catch(PlayerLync\Exceptions\PlayerLyncSDKException $e)
{
  // When PlayerLync SDK fails or some other local issue
  echo 'PlayerLync SDK returned an error: ' . $e->getMessage();
  exit;
}

try
{
  $playerlync = new \PlayerLync\PlayerLync([/*.....*/]);

  //FILE UPLOAD EXAMPLE
  $existingFileId = '<fileID GUID>';
  $filePath = '/path/to/your/file.txt';

  $data = [
      'fileid' => $existingFileId,
      'sourcefile' => $playerlync->fileToUpload($filePath)
  ];

  $response = $playerlync->post('/files', $data);

  $body = $response->getDecodedBody(); //get the full decoded JSON response
  $file = $response->getData(); //get just the "data" object from the decoded JSON response
}
catch(PlayerLync\Exceptions\PlayerLyncResponseException $e)
{
  // When PlayerLync API returns an error
  echo 'PlayerLync API returned an error: ' . $e->getMessage();
  exit;
}
catch(PlayerLync\Exceptions\PlayerLyncSDKException $e)
{
  // When PlayerLync SDK fails or some other local issue
  echo 'PlayerLync SDK returned an error: ' . $e->getMessage();
  exit;
}
json
{
  "yerlync/playerlync-sdk-php" : "4000.1.*"
  }
}