You are on page 1of 11

@ineon03 : ineon03@live.com tutorial OAuth google drive / google apps.

Step Create Google Drive Token

 Create google project


 Create API Key
 Create OAuth Client ID
 Authorize ClientID & Generate Code
 Generate Token & Refresh Token
 Re-Generate Token menggunakan Refresh Token
 Automate menggunakan Talend.

A. CREATE GOOGLE PROJECT


1. Login ke https://console.developers.google.com/apis/library, pilih Google Apps API : Drive API

2. Click Create Project :

3. Click lagi tombol create project di halaman berikutnya :


@ineon03 : ineon03@live.com tutorial OAuth google drive / google apps.

4. Isi form:
Project name: DataReportTalend
Please email.. : NO
I Aggree : Yes
Tekan tombol CREATE

B. CREATE API KEY


1. Tekan tombol Enable :
@ineon03 : ineon03@live.com tutorial OAuth google drive / google apps.

2. Buat Credential dengan click tombol berikut :

3. Create link API Key :


@ineon03 : ineon03@live.com tutorial OAuth google drive / google apps.

4. Isi dengan Name : Talend Access , Pilih None di Key Restriction lalu tekan create :
@ineon03 : ineon03@live.com tutorial OAuth google drive / google apps.

5. Simpan API Key yang diperoleh :


Misal : AIzaSyAW8kdiaWJ_8NggNbaGuiXZHO5PmZOP1_w

C. CREATE OAUTH CLIENT ID


@ineon03 : ineon03@live.com tutorial OAuth google drive / google apps.

1. Kembali ke Credential Screen, Click segitiga kecil di create Credential pilih OAuth ClientID :

2. Pilih Other dan beri nama Talend Access , click Create :

3. Simpan ClientID dan Secret yang dihasilkan :


ClientID : 47791333416-
bm0g76ksqaibn1h4cnq813romlps004t.apps.googleusercontent.com
Secret : h1hc14QaXynEHH77KRr1OC4d
@ineon03 : ineon03@live.com tutorial OAuth google drive / google apps.

D. AUTHORIZE CLIENTID & GENERATE CODE


1. Buat link dengan format berikut, update client_id value dengan clientID yang diperoleh dari step
sebelumnya :
https://accounts.google.com/o/oauth2/auth?
scope=email%20profile%20https://www.googleapis.com/auth/drive&
state=security_token%3D138r5719ru3e1%26url%3Dhttps://oa2cb.example.com/myHome&
redirect_uri=urn:ietf:wg:oauth:2.0:oob&
response_type=code&
client_id=47791333416-bm0g76ksqaibn1h4cnq813romlps004t.apps.googleusercontent.com &
access_type=offline

Link :

https://accounts.google.com/o/oauth2/auth?scope=email%20profile%20https://www.google
apis.com/auth/drive&state=security_token%3D138r5719ru3e1%26url%3Dhttps://oa2cb.exa
mple.com/myHome&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id
=47791333416-
bm0g76ksqaibn1h4cnq813romlps004t.apps.googleusercontent.com&access_type=offline

2. Paste link ke browser dan click Allow :


@ineon03 : ineon03@live.com tutorial OAuth google drive / google apps.

3. Keluar code dan simpan code tersebut :

4/SnP9lJ9jclJjI_kK0pYCMcBpPGowfAl4zTlvKDJ_x58

Saat ini kita sudah memiliki :

ClientID : 47791333416-
bm0g76ksqaibn1h4cnq813romlps004t.apps.googleusercontent.com
Secret : h1hc14QaXynEHH77KRr1OC4d
Code : 4/SnP9lJ9jclJjI_kK0pYCMcBpPGowfAl4zTlvKDJ_x58

E. GENERATE TOKEN & REFRESH TOKEN


1. Install Google Extension : REST Console :
 Dari chrome, buka :
https://www.google.co.id/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact
=8&ved=0ahUKEwjGgtifnc3RAhXIwI8KHQfYBJ4QFggbMAA&url=https%3A%2F%2Fchrom
e.google.com%2Fwebstore%2Fdetail%2Fadvanced-rest-
@ineon03 : ineon03@live.com tutorial OAuth google drive / google apps.

client%2Fhgmloofddffdnphfgcellkdfbfbjeloo&usg=AFQjCNEo489FdO7M0eVz4c9u475vR
OBbXQ&sig2=QUcVn8HFYPlNYLF0W-iNSw


 Klik TAMBAH KE CHROME
2. Buat link dengan format :

https://www.googleapis.com/oauth2/v3/token?
code={code}&
client_id={client_id}&
client_secret={client_secret}&
redirect_uri=urn:ietf:wg:oauth:2.0:oob&
grant_type=authorization_code

Url :

https://www.googleapis.com/oauth2/v3/token?code=4/SnP9lJ9jclJjI_kK0pYCMcBpPGowfAl4zTlvKDJ_x
58&client_id=47791333416-
bm0g76ksqaibn1h4cnq813romlps004t.apps.googleusercontent.com&client_secret=h1hc
14QaXynEHH77KRr1OC4d&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_
code

3. Buka Rest Console :


Ctrl+T, Application :
@ineon03 : ineon03@live.com tutorial OAuth google drive / google apps.

Masukkan url yang sudah terbentuk ke kolom request.


Pilih application/x-www-form di variable
Pilih POST

Tekan tombol SEND, hasilnya :

Dari sini kita dapatkan :


@ineon03 : ineon03@live.com tutorial OAuth google drive / google apps.

access_token:
ya29.GlvYAywhnA_Ox8kmARFH4KuTsx722K1LVakPk9eL78jmwkAHRMRB9GFST4oHS2Iys7G
Fpiy3xAeHyd2dbphjxpvWkEUTDypXjOYGLvn3bqNIUb6q8dBuTEgeB9e4

refresh_token: 1/i-q2bcFmqfk4XORWxSNauhG5H3hnqpZ7QUGf-z1Rr-A

Dari sini sudah didapat access_token dan bisa digunakan, tetapi umurnya hanya 1jam.

F. RE-GENERATE TOKEN MENGGUNAKAN REFRESH TOKEN


1. Jika sudah expire dan perlu access_token lagi, dapat call api token lagi , buat :

https://www.googleapis.com/oauth2/v3/token?
client_id={CLIENT_ID}&
client_secret={SECRET}&
refresh_token={REFRESH_TOKEN}&
grant_type=refresh_token

Contoh :

https://www.googleapis.com/oauth2/v3/token?
client_id=47791333416-
bm0g76ksqaibn1h4cnq813romlps004t.apps.googleusercontent.com&
client_secret=h1hc14QaXynEHH77KRr1OC4d&
refresh_token=1/i-q2bcFmqfk4XORWxSNauhG5H3hnqpZ7QUGf-z1Rr-A

2. Sama seperti proses create token di atas menggunakan REST Client.

G. AUTOMATE MENGGUNAKAN TALEND


1. Diperlukan 3 variable yang sudah diketahui :
 clientID
 Client_Secret
 Refresh_Token
2. Contoh di talend jobs UploadCloud
3.

Copy protected with Online-PDF-No-Copy.com

You might also like