0
import requests
import json

url = "http://www.theguardian.com/world/2014/oct/01/ebola-us-doctors-texas-liberia"
api = 'http://graph.facebook.com/?id='
r = requests.get(api + url)
data = r.text
x = json.loads(data)
if 'shares' in x:
    try:
        print 'Facebook shares', x['shares']
    except:
        pass

This script used to get the Facebook shares/likes from a given webpage, however, today it stopped working. Did they change the API, or something different is wrong?

Zlo
  • 1,150
  • 2
  • 18
  • 38
  • What does the HTTP request return? – WizKid Oct 01 '14 at 23:29
  • `{u'error': {u'message': u'(#4) Application request limit reached', u'code': 4, u'type': u'OAuthException'}}` Could it be that I expired API requests? – Zlo Oct 01 '14 at 23:35
  • 2
    No you are just doing too many. Add an access token and you will be able to do more – WizKid Oct 02 '14 at 00:47

1 Answers1

1

It should work also, it`s better to use r.json() directly to convert it to json rather than r.text and then using json.loads

import requests
import json

url = "http://www.theguardian.com/world/2014/oct/01/ebola-us-doctors-texas-liberia"
api = 'http://graph.facebook.com/?id='
r = requests.get(api + url)
data = r.json()
if 'share' in data:
    try:
        print 'Facebook shares', data['shares']
    except:
        pass

use of pass is not recommended according to source

Community
  • 1
  • 1
shobhit_mittal
  • 113
  • 2
  • 5