-
-
Save xmunoz/5640569 to your computer and use it in GitHub Desktop.
Google Device Authentication and Google Calendar API requests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@artemis:~# curl -d "client_id={ID}.apps.googleusercontent.com&scope=https://www.googleapis.com/auth/calendar" https://accounts.google.com/o/oauth2/device/code | |
{ | |
"device_code" : {DEVICE_CODE}, | |
"user_code" : {USER_CODE}, | |
"verification_url" : "http://www.google.com/device", | |
"expires_in" : 1800, | |
"interval" : 5 | |
} | |
root@artemis:~#curl -d "client_id={ID}.apps.googleusercontent.com&client_secret={SECRET}&code={DEVICE_CODE}&grant_type=http://oauth.net/grant_type/device/1.0" https://accounts.google.com/o/oauth2/token | |
{ | |
"access_token" : {ACCESS_TOKEN}, | |
"token_type" : "Bearer", | |
"expires_in" : 3600, | |
"refresh_token" : {REFRESH_TOKEN} | |
} | |
----------------------------------- | |
#!/usr/bin/env python | |
import requests | |
import json | |
headers = { | |
'Content-Type': 'application/json', | |
'Authorization': 'Bearer {ACCESS_TOKEN}' | |
} | |
url = 'https://www.googleapis.com/calendar/v3/calendars/{CAL_ID}/events' | |
json_data=open('dumped_screenings.json') | |
payload = json.load(json_data) | |
for data in payload: | |
json_data = json.dumps(data) | |
# one api request/event per screening | |
r = requests.post(url, data=json_data, headers=headers) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is effectively a working example of this. The json for this script was generated by my scraper.