Sunday 8 February 2015

Pushbullet API: Pushing stuff with Python

Posted By: Unknown - 10:20

Share

& Comment


Hey, it has been a long time since I posted some stuff. So, here I'm with a simple but useful stuff for you guys out there. If you're wondering what Pushbullet is, well, here's what it is

"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!

About Unknown

Hi. I'm a freelancer software developer, also interested in exploit development, reverse engineering and web development. Here I'll be sharing stuff I find interesting. Feel free to swing by the blog!

0 comments:

Post a Comment

Copyright © 2013 Coding The Void™ is a registered trademark.

Designed by Templateism. Hosted on Blogger Platform.