Google Drive

Google Drive is a storage platform that allows users to access their data from any device or application. Users rely on Drive to store all of their data, while third-party applications rely on Drive to enable rich and contextual features for this data. To access drive services you need to grab an access token by authenticating first. The analytics scope when generating a URL can be passed by simply setting 'drive' to getLoginURL(). Figure 1 shows how we can obtain an access token for Google Drive.

Figure 1. Authentication
session_start();

$auth = eden('google')->auth('[CLIENT_ID]', '[CLIENT_SECRET]', 'http://yourwebsite.com/auth', '[API_KEY]');

//if no code and no session
if(!isset($_GET['code']) && !isset($_SESSION['token'])) {
    //redirect to login
    $login = $auth->getLoginUrl('drive');
    header('Location: '.$login);
    exit;
}

//Code is returned back from google
if(isset($_GET['code'])) {
    //save it to session
	$access = $auth->getAccess($_GET['code']);
    $_SESSION['token'] = $access['access_token'];
	
}

When we have our token we can then access the different service levels of Google Drive.

Figure 2. Instantiate Drive
$drive = eden('google')->drive($_SESSION['token']);
Figure 3. Drive Methods
Method Arguments Returns Description
$drive->changes(); none Eden_Google_Drive_Changes Returns Google Drive Changes
$drive->children(); none Eden_Google_Drive_Children Returns Google Drive Children
$drive->files(); none Eden_Google_Drive_Files Returns Google Drive Files
$drive->getAbout(); none array Gets the information about the current user along with Drive API settings
$drive->getApps(); none array Lists a user's apps.
$drive->parents(); none Eden_Google_Drive_Parent Returns Google Drive parent
$drive->permissions(); none Eden_Google_Drive_Permissions Returns Google Drive Permissions
$drive->revisions(); none Eden_Google_Drive_Revisions Returns Google Drive Revisions

© 2012 Openovate Labs. All rights reserved.