Google 2
-
Upload
sy-buenavista -
Category
Documents
-
view
175 -
download
3
Transcript of Google 2
Go to https://code.google.com/apis/console
Authentication1. Get API Access
$clientId = ‘YOUR_CLIENT_ID’;$clientSecret = ‘YOUR_CLIENT_SECRET’;$redirectUrl = ‘'http://yourwebsite.com/’;
$auth = eden(‘google')->auth($clientId , $clientSecret , $redirectUrl);
Authentication2. Get Login URL$scope = array(
‘SCOPE_URL_FROM_GOOGLE');$login = $auth ->getLoginUrl($scope);echo $login;
Authentication2. Get Login URL$scope = array(
' https://www.googleapis.com/auth/drive');$login = $auth ->getLoginUrl($scope);echo $login;
Authentication2. Get Login URL‘https://accounts.google.com/o/oauth2/auth?
response_type=code&client_id=1021817912223.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Feden.eden.ph%2F&access_type=online&approval_prompt=auto&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.file+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.me’
Authentication2. Get Login URL
Authentication3. Get Token
$access = $auth->getAccess($_GET['code']);print_r($access);
Authentication3. Get Token
//start sessionsession_start();//get auth$auth = eden(‘google’)->auth($clientId, $clientSecret, $redirect); //if no code and no sessionif(!isset($_GET['code']) && !isset($_SESSION[‘google_token'])) {
//redirect to login$login = $auth- >getLoginUrl();header('Location: '.$login);exit;
}
//Code is returned back from googleif(isset($_GET['code'])) { //save it to session
$access = $auth->getAccess($_GET['code']);$_SESSION[‘google_token'] = $access['access_token'];
}
Google Drive
Google Drive
//Instantiate Google Drive Class$drive = eden('google')
->drive(‘[YOUR_ACCESS_TOKEN]’);
Google Drive
//Instantiate Google Drive Class$drive = eden('google')
->drive(‘ya29.AHES6ZSNBMKBaoge1dF6zmAkIgJd9Gp
aXt6MlodxuoPSB259fi1djw’);
Google DriveGet user drive files
$files = $drive->files()->getList();
print_r($files);
Google DriveGet user drive specific files
$files = $drive->files()->getSpecific(‘[FILE_ID]’);
print_r($files);
Google DriveMove file to trash
$files = $drive->files()->trash(‘[FILE_ID]’);
print_r($files);
Google DriveDelete a file
$files = $drive->files()->delete(‘[FILE_ID]’);
print_r($files);
http://pastie.org/5385973