Skip to content

Instantly share code, notes, and snippets.

@xmunoz
Created May 24, 2013 00:41
Show Gist options
  • Save xmunoz/5640569 to your computer and use it in GitHub Desktop.
Save xmunoz/5640569 to your computer and use it in GitHub Desktop.
Google Device Authentication and Google Calendar API requests.
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)
@xmunoz
Copy link
Author

xmunoz commented May 24, 2013

This is effectively a working example of this. The json for this script was generated by my scraper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment