SlideShare une entreprise Scribd logo
1  sur  17
Go to https://code.google.com/apis/console
Authentication
1. Get API Access
$clientId        = ‘YOUR_CLIENT_ID’;
$clientSecret    = ‘YOUR_CLIENT_SECRET’;
$redirectUrl     = ‘'http://yourwebsite.com/’;

$auth = eden(‘google')
->auth($clientId , $clientSecret , $redirectUrl);
Authentication
2. Get Login URL
$scope = array(
  ‘SCOPE_URL_FROM_GOOGLE');
$login = $auth ->getLoginUrl($scope);
echo $login;
Authentication
2. Get Login URL
$scope = array(
  ' https://www.googleapis.com/auth/drive');
$login = $auth ->getLoginUrl($scope);
echo $login;
Authentication
2. Get Login URL
‘https://accounts.google.com/o/oauth2/auth?re
   sponse_type=code&client_id=1021817912223.
   apps.googleusercontent.com&redirect_uri=htt
   p%3A%2F%2Feden.eden.ph%2F&access_type=
   online&approval_prompt=auto&scope=https%
   3A%2F%2Fwww.googleapis.com%2Fauth%2Fd
   rive.file+https%3A%2F%2Fwww.googleapis.co
   m%2Fauth%2Fdrive+https%3A%2F%2Fwww.go
   ogleapis.com%2Fauth%2Fplus.me’
Authentication
2. Get Login URL
Authentication
3. Get Token

$access = $auth->getAccess($_GET['code']);
print_r($access);
Authentication
3. Get Token
//start session
session_start();
//get auth
$auth = eden(‘google’)->auth($clientId, $clientSecret, $redirect);

//if no code and no session
if(!isset($_GET['code']) && !isset($_SESSION*‘google_token'])) {
    //redirect to login
    $login = $auth- >getLoginUrl();
    header('Location: '.$login);
    exit;
}
//Code is returned back from google
if(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 Drive
Get user drive files

$files = $drive
 ->files()
 ->getList();

print_r($files);
Google Drive
Get user drive specific files

$files = $drive
 ->files()
 ->getSpecific(‘[FILE_ID]’);

print_r($files);
Google Drive
Move file to trash

$files = $drive
 ->files()
 ->trash(‘[FILE_ID]’);

print_r($files);
Google Drive
Delete a file

$files = $drive
 ->files()
 ->delete(‘[FILE_ID]’);

print_r($files);
http://pastie.org/5385973

Contenu connexe

Tendances

Building Persona: federated and privacy-sensitive identity for the Web (Open ...
Building Persona: federated and privacy-sensitive identity for the Web (Open ...Building Persona: federated and privacy-sensitive identity for the Web (Open ...
Building Persona: federated and privacy-sensitive identity for the Web (Open ...Francois Marier
 
Building Persona: federated and privacy-sensitive identity for the Web (LCA 2...
Building Persona: federated and privacy-sensitive identity for the Web (LCA 2...Building Persona: federated and privacy-sensitive identity for the Web (LCA 2...
Building Persona: federated and privacy-sensitive identity for the Web (LCA 2...Francois Marier
 
HirshHorn theme: how I created it
HirshHorn theme: how I created itHirshHorn theme: how I created it
HirshHorn theme: how I created itPaul Bearne
 
The Web beyond "usernames & passwords" (OSDC12)
The Web beyond "usernames & passwords" (OSDC12)The Web beyond "usernames & passwords" (OSDC12)
The Web beyond "usernames & passwords" (OSDC12)Francois Marier
 
Introduction to ZendX jQuery
Introduction to ZendX jQueryIntroduction to ZendX jQuery
Introduction to ZendX jQuerydennisdc
 
Essentials for Implementers Certificate
Essentials for Implementers CertificateEssentials for Implementers Certificate
Essentials for Implementers CertificateRoberta Pereira
 
Sample portfolio1
Sample portfolio1Sample portfolio1
Sample portfolio1mkboudewyns
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 
Building secured wordpress themes and plugins
Building secured wordpress themes and pluginsBuilding secured wordpress themes and plugins
Building secured wordpress themes and pluginsTikaram Bhandari
 
Security and Mobility - WordCamp Porto 2016
Security and Mobility - WordCamp Porto 2016Security and Mobility - WordCamp Porto 2016
Security and Mobility - WordCamp Porto 2016Marcel Schmitz
 
Nette framework (WebElement #27 lightning talk)
Nette framework (WebElement #27 lightning talk)Nette framework (WebElement #27 lightning talk)
Nette framework (WebElement #27 lightning talk)Adam Štipák
 
Twitter bootstrap
Twitter bootstrapTwitter bootstrap
Twitter bootstrapdennisdc
 
Iste 2011 googlespatial kolvoord
Iste 2011 googlespatial kolvoordIste 2011 googlespatial kolvoord
Iste 2011 googlespatial kolvoordpapersh21
 
How kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonHow kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonKris Wallsmith
 

Tendances (19)

Building Persona: federated and privacy-sensitive identity for the Web (Open ...
Building Persona: federated and privacy-sensitive identity for the Web (Open ...Building Persona: federated and privacy-sensitive identity for the Web (Open ...
Building Persona: federated and privacy-sensitive identity for the Web (Open ...
 
Building Persona: federated and privacy-sensitive identity for the Web (LCA 2...
Building Persona: federated and privacy-sensitive identity for the Web (LCA 2...Building Persona: federated and privacy-sensitive identity for the Web (LCA 2...
Building Persona: federated and privacy-sensitive identity for the Web (LCA 2...
 
HirshHorn theme: how I created it
HirshHorn theme: how I created itHirshHorn theme: how I created it
HirshHorn theme: how I created it
 
The Web beyond "usernames & passwords" (OSDC12)
The Web beyond "usernames & passwords" (OSDC12)The Web beyond "usernames & passwords" (OSDC12)
The Web beyond "usernames & passwords" (OSDC12)
 
Php if
Php ifPhp if
Php if
 
Introduction to ZendX jQuery
Introduction to ZendX jQueryIntroduction to ZendX jQuery
Introduction to ZendX jQuery
 
DBI
DBIDBI
DBI
 
Essentials for Implementers Certificate
Essentials for Implementers CertificateEssentials for Implementers Certificate
Essentials for Implementers Certificate
 
Sample portfolio1
Sample portfolio1Sample portfolio1
Sample portfolio1
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Building secured wordpress themes and plugins
Building secured wordpress themes and pluginsBuilding secured wordpress themes and plugins
Building secured wordpress themes and plugins
 
Security and Mobility - WordCamp Porto 2016
Security and Mobility - WordCamp Porto 2016Security and Mobility - WordCamp Porto 2016
Security and Mobility - WordCamp Porto 2016
 
Nette framework (WebElement #27 lightning talk)
Nette framework (WebElement #27 lightning talk)Nette framework (WebElement #27 lightning talk)
Nette framework (WebElement #27 lightning talk)
 
Twitter bootstrap
Twitter bootstrapTwitter bootstrap
Twitter bootstrap
 
Iste 2011 googlespatial kolvoord
Iste 2011 googlespatial kolvoordIste 2011 googlespatial kolvoord
Iste 2011 googlespatial kolvoord
 
画像Hacks
画像Hacks画像Hacks
画像Hacks
 
How kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonHow kris-writes-symfony-apps-london
How kris-writes-symfony-apps-london
 
Migrare da symfony 1 a Symfony2
 Migrare da symfony 1 a Symfony2  Migrare da symfony 1 a Symfony2
Migrare da symfony 1 a Symfony2
 
Practica csv
Practica csvPractica csv
Practica csv
 

En vedette

Reunió pares llar novembre 2013
Reunió pares llar novembre 2013Reunió pares llar novembre 2013
Reunió pares llar novembre 2013mediasinguerlin
 
Reunió Inici de Curs P-4
Reunió Inici de Curs P-4Reunió Inici de Curs P-4
Reunió Inici de Curs P-4mediasinguerlin
 
Big data analytics and its impact on internet users
Big data analytics and its impact on internet usersBig data analytics and its impact on internet users
Big data analytics and its impact on internet usersStruggler Ever
 
You Can't Miss What You Can't Measure
You Can't Miss What You Can't MeasureYou Can't Miss What You Can't Measure
You Can't Miss What You Can't MeasureKerri Miller
 
Reunió pares llar juny ok
Reunió pares llar  juny okReunió pares llar  juny ok
Reunió pares llar juny okmediasinguerlin
 
Intel modun3 bakhtran
Intel modun3 bakhtranIntel modun3 bakhtran
Intel modun3 bakhtranBakh Tran
 
Как я зимовала 2015
Как я зимовала 2015Как я зимовала 2015
Как я зимовала 2015Anna Stetsenko
 
An online flea market in higher education using c2 c e commerce model a requi...
An online flea market in higher education using c2 c e commerce model a requi...An online flea market in higher education using c2 c e commerce model a requi...
An online flea market in higher education using c2 c e commerce model a requi...Struggler Ever
 
Bo cau hoi dinh huong su no vi nhiet cua vat ran
Bo cau hoi dinh huong su no vi nhiet cua vat ranBo cau hoi dinh huong su no vi nhiet cua vat ran
Bo cau hoi dinh huong su no vi nhiet cua vat ranBakh Tran
 
Indigo: Как в Украине найти сейла на миллион
Indigo: Как в Украине найти сейла на миллионIndigo: Как в Украине найти сейла на миллион
Indigo: Как в Украине найти сейла на миллионAnna Stetsenko
 
Девушки пишут первыми только в Linkedin ver 3.1
Девушки пишут первыми только в Linkedin ver 3.1Девушки пишут первыми только в Linkedin ver 3.1
Девушки пишут первыми только в Linkedin ver 3.1Anna Stetsenko
 
Indigo: Afterparty Recruiting для Найти Ответ №10
Indigo: Afterparty Recruiting для Найти Ответ №10 Indigo: Afterparty Recruiting для Найти Ответ №10
Indigo: Afterparty Recruiting для Найти Ответ №10 Anna Stetsenko
 

En vedette (17)

Reunió pares llar novembre 2013
Reunió pares llar novembre 2013Reunió pares llar novembre 2013
Reunió pares llar novembre 2013
 
Portaventura
PortaventuraPortaventura
Portaventura
 
Reunió Inici de Curs P-4
Reunió Inici de Curs P-4Reunió Inici de Curs P-4
Reunió Inici de Curs P-4
 
Laboratory practice
Laboratory practiceLaboratory practice
Laboratory practice
 
Big data analytics and its impact on internet users
Big data analytics and its impact on internet usersBig data analytics and its impact on internet users
Big data analytics and its impact on internet users
 
Experiencia olivieri
Experiencia olivieriExperiencia olivieri
Experiencia olivieri
 
You Can't Miss What You Can't Measure
You Can't Miss What You Can't MeasureYou Can't Miss What You Can't Measure
You Can't Miss What You Can't Measure
 
Google 0
Google 0Google 0
Google 0
 
Reunió pares llar juny ok
Reunió pares llar  juny okReunió pares llar  juny ok
Reunió pares llar juny ok
 
SCF NE Group Orientation 2011 ppt Sierra Club Florida
SCF NE Group Orientation 2011 ppt Sierra Club FloridaSCF NE Group Orientation 2011 ppt Sierra Club Florida
SCF NE Group Orientation 2011 ppt Sierra Club Florida
 
Intel modun3 bakhtran
Intel modun3 bakhtranIntel modun3 bakhtran
Intel modun3 bakhtran
 
Как я зимовала 2015
Как я зимовала 2015Как я зимовала 2015
Как я зимовала 2015
 
An online flea market in higher education using c2 c e commerce model a requi...
An online flea market in higher education using c2 c e commerce model a requi...An online flea market in higher education using c2 c e commerce model a requi...
An online flea market in higher education using c2 c e commerce model a requi...
 
Bo cau hoi dinh huong su no vi nhiet cua vat ran
Bo cau hoi dinh huong su no vi nhiet cua vat ranBo cau hoi dinh huong su no vi nhiet cua vat ran
Bo cau hoi dinh huong su no vi nhiet cua vat ran
 
Indigo: Как в Украине найти сейла на миллион
Indigo: Как в Украине найти сейла на миллионIndigo: Как в Украине найти сейла на миллион
Indigo: Как в Украине найти сейла на миллион
 
Девушки пишут первыми только в Linkedin ver 3.1
Девушки пишут первыми только в Linkedin ver 3.1Девушки пишут первыми только в Linkedin ver 3.1
Девушки пишут первыми только в Linkedin ver 3.1
 
Indigo: Afterparty Recruiting для Найти Ответ №10
Indigo: Afterparty Recruiting для Найти Ответ №10 Indigo: Afterparty Recruiting для Найти Ответ №10
Indigo: Afterparty Recruiting для Найти Ответ №10
 

Similaire à Get Google Drive files and authentication with PHP

17. CodeIgniter login simplu cu sesiuni
17. CodeIgniter login simplu cu sesiuni17. CodeIgniter login simplu cu sesiuni
17. CodeIgniter login simplu cu sesiuniRazvan Raducanu, PhD
 
PHPUnit with Mocking and Crawling
PHPUnit with Mocking and CrawlingPHPUnit with Mocking and Crawling
PHPUnit with Mocking and CrawlingTrung x
 
Integrating OAuth and Social Login Into Wordpress
Integrating OAuth and Social Login Into WordpressIntegrating OAuth and Social Login Into Wordpress
Integrating OAuth and Social Login Into WordpressWilliam Tam
 
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe KyivKISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe KyivGrossum Software Outsourcing
 
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe KyivKISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe KyivGrossum
 
Document
DocumentDocument
Documentviwviw
 
Smart Lock for Password @ Game DevFest Bangkok 2015
Smart Lock for Password @ Game DevFest Bangkok 2015Smart Lock for Password @ Game DevFest Bangkok 2015
Smart Lock for Password @ Game DevFest Bangkok 2015Somkiat Khitwongwattana
 
Saferpay Checkout Page - PHP Sample (Hosting)
Saferpay Checkout Page - PHP Sample (Hosting)Saferpay Checkout Page - PHP Sample (Hosting)
Saferpay Checkout Page - PHP Sample (Hosting)webhostingguy
 
You're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp OrlandoYou're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp OrlandoChris Scott
 
Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)Nordic APIs
 
Drupal sins 2016 10-06
Drupal sins 2016 10-06Drupal sins 2016 10-06
Drupal sins 2016 10-06Aaron Crosman
 
Unit 3 - for php application Sessions.pptx
Unit 3  -  for php  application Sessions.pptxUnit 3  -  for php  application Sessions.pptx
Unit 3 - for php application Sessions.pptxmythili213835
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012D
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Fabien Potencier
 
Passwords suck, but centralized proprietary services are not the answer
Passwords suck, but centralized proprietary services are not the answerPasswords suck, but centralized proprietary services are not the answer
Passwords suck, but centralized proprietary services are not the answerFrancois Marier
 
Security in laravel
Security in laravelSecurity in laravel
Security in laravelSayed Ahmed
 

Similaire à Get Google Drive files and authentication with PHP (20)

17. CodeIgniter login simplu cu sesiuni
17. CodeIgniter login simplu cu sesiuni17. CodeIgniter login simplu cu sesiuni
17. CodeIgniter login simplu cu sesiuni
 
PHPUnit with Mocking and Crawling
PHPUnit with Mocking and CrawlingPHPUnit with Mocking and Crawling
PHPUnit with Mocking and Crawling
 
Integrating OAuth and Social Login Into Wordpress
Integrating OAuth and Social Login Into WordpressIntegrating OAuth and Social Login Into Wordpress
Integrating OAuth and Social Login Into Wordpress
 
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe KyivKISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
 
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe KyivKISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
KISS: Keep It Simple Security - Oleg Zinchenko - Symfony Cafe Kyiv
 
logic321
logic321logic321
logic321
 
Document
DocumentDocument
Document
 
Smart Lock for Password @ Game DevFest Bangkok 2015
Smart Lock for Password @ Game DevFest Bangkok 2015Smart Lock for Password @ Game DevFest Bangkok 2015
Smart Lock for Password @ Game DevFest Bangkok 2015
 
Saferpay Checkout Page - PHP Sample (Hosting)
Saferpay Checkout Page - PHP Sample (Hosting)Saferpay Checkout Page - PHP Sample (Hosting)
Saferpay Checkout Page - PHP Sample (Hosting)
 
You're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp OrlandoYou're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp Orlando
 
Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)Do you want a SDK with that API? (Nordic APIS April 2014)
Do you want a SDK with that API? (Nordic APIS April 2014)
 
Drupal sins 2016 10-06
Drupal sins 2016 10-06Drupal sins 2016 10-06
Drupal sins 2016 10-06
 
Daily notes
Daily notesDaily notes
Daily notes
 
Unit 3 - for php application Sessions.pptx
Unit 3  -  for php  application Sessions.pptxUnit 3  -  for php  application Sessions.pptx
Unit 3 - for php application Sessions.pptx
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012
 
CakePHP workshop
CakePHP workshopCakePHP workshop
CakePHP workshop
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2
 
Mashing up JavaScript
Mashing up JavaScriptMashing up JavaScript
Mashing up JavaScript
 
Passwords suck, but centralized proprietary services are not the answer
Passwords suck, but centralized proprietary services are not the answerPasswords suck, but centralized proprietary services are not the answer
Passwords suck, but centralized proprietary services are not the answer
 
Security in laravel
Security in laravelSecurity in laravel
Security in laravel
 

Get Google Drive files and authentication with PHP