PHP code example of yuudrive / drive-sdk

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

    

yuudrive / drive-sdk example snippets


// include your composer dependencies
nt_id = "YOUR_CLIENT_ID_HERE";
$client_secret = "YOUR_SECRET_KEY_HERE";
$developer_key = "YOUR_DEV_KEY_HERE";
$redirect_uri = 'http://example.com/callback';

$client = new Client($client_id, $client_secret, $developer_key, $redirect_uri);

$authURI = $client->authURI();

$fetchToken = $client->fetchAccessTokenWithAuthCode($code)->getResponse();

print_r($fetchToken->data); // return raw response
echo $fetchToken->getAccessToken() // return access_token attribute
echo $fetchToken->getRefreshToken() // return refresh_token attribute

$fetchToken = $client->fetchAccessTokenWithRefreshToken($refresh_token)->getResponse();

print_r($fetchToken->data); // return raw response
echo $fetchToken->getAccessToken() // return access_token attribute
echo $fetchToken->getRefreshToken() // return refresh_token attribute

$client->revokeAccessToken($access_token);

// passing access token parameter
$client->profile($access_token);

// OR

$client->setAccessToken($access_token);
$profile = $client->profile()->getResponse();

// attributes:
$profile->getId(); // get User id
$profile->getEmail(); // user email
$profile->getName(); // name
$profile->getPicture(); // profile picture

$client->setAccessToken($access_token);
$file = $client->getFile($file_id)->getResponse();

//attributes:
$file->getId(); // file id
$file->getName(); // file name
$file->getSize(); // file size
$file->getExtention(); // file extention
$file->getChecksum(); // file checksum

$client->setAccessToken($access_token);
$files = $client->getFiles()->getResponse();

// only return the file list
$files->showFileOnly();

// only return the folder list
$files->showFolderOnly();


$client->setAccessToken($access_token);
$create_folder = $client->folder($folder_name)->setRole('reader')->setPermissionType('anyone');

// to set folder color
->colorRgb($rgb_code);

// to set folder starred
->starred(true);

//execute instance
$create_folder = $create_folder->create()->getResponse();

print_r($create_folder->data); // to return object response