Skip to content

Instantly share code, notes, and snippets.

@revox
Created December 9, 2015 12:03
Show Gist options
  • Save revox/f6905fdf9fec5d38ed93 to your computer and use it in GitHub Desktop.
Save revox/f6905fdf9fec5d38ed93 to your computer and use it in GitHub Desktop.
Get the like/share counts for a URL
import requests, json
target_url = "http://www.bbc.co.uk/news/blogs-magazine-monitor-30742506"
apis = ['http://graph.facebook.com/?id=', 'http://cdn.api.twitter.com/1/urls/count.json?url=']
# http://graph.facebook.com/?id= # facebook shares api
# http://cdn.api.twitter.com/1/urls/count.json?url= # twitter shares api
for api in apis:
url = api + target_url
content = requests.get(url).json()
try:
if content['shares']:
print 'FaceBook shares ', content['shares']
except:
pass
try:
if content['count']:
print 'Twitter shares ', content['count']
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment