"Pushbullet bridges the gap between your phone, tablet, and computer, enabling them to work better together. From seeing your phone's notifications on your computer, to easily transferring links, files, and more between devices, Pushbullet saves you time by making what used to be difficult or impossible, easy." - Pushbullet.com
You should definitely give it a try.
Now that we know how awesome it is, let's create a simple script to retrieve user/device info and push a link to all devices using the Pushbullet API. All you need is the access token of your account registered with the Pushbullet server. Go to your Account Settings to get it.
PushbulletAPI_Devices.py
__author__ = 'codingthevoid' import json import urllib2 # Access Token pbActionToken = '' # Target URL to get all devices targetUrl = 'https://api.pushbullet.com/v2/devices' # Setup required HTTP request headers headers = { 'Content-Type' : 'application/json', 'Authorization' : 'Bearer ' + pbActionToken } # Create a HTTP request object reqObj = urllib2.Request(targetUrl, None, headers) # Open the target URL and get the response. response = urllib2.urlopen(reqObj) # Decode the JSON response and print it print(json.loads(response.read()))
... and here's how to push a link to all the devices connected to your account
PushbulletAPI_PushLink.py
__author__ = 'codingthevoid' import json import urllib2 # Access Token pbActionToken = '' # Target URL to push stuff to all devices targetUrl = 'https://api.pushbullet.com/v2/pushes' # Setup required HTTP request headers headers = { 'Content-Type' : 'application/json', 'Authorization' : 'Bearer ' + pbActionToken } # Pushing a link with title "My URL title!", message "Some message", and the url "http://codingthevoid.blogspot.in/" values = { 'type' : 'link', 'title' : 'My URL title!', 'body' : 'Some message', 'url' : 'http://codingthevoid.blogspot.in/' } # JSON encode the request body. jsonEncodedValues = json.dumps(values) # Create a HTTP POST request object reqObj = urllib2.Request(targetUrl, jsonEncodedValues, headers) # Open the target URL and get the response. response = urllib2.urlopen(reqObj) # Decode the JSON response and print it print(json.loads(response.read()))
Just replace your access token with "<access_token>" and you're good to go. Feel free to extend this and implement other features the Pushbullet API has to offer you. Don't forget to share. Enjoy!
0 comments:
Post a Comment