Skip to content

Instantly share code, notes, and snippets.

@yahelc
Created September 15, 2011 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yahelc/57028738e649c15c3b15 to your computer and use it in GitHub Desktop.
Save yahelc/57028738e649c15c3b15 to your computer and use it in GitHub Desktop.
Getting +1 counts in Python using GAE urlfetch
from google.appengine.api import urlfetch
totals = {}
result = urlfetch.fetch(url="https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ", payload=form_fields, method=urlfetch.POST, headers={'Content-Type': 'application/json'})
plusone = json.loads(result.content)
try:
totals["GooglePlusOne"] = int(plusone[0][u"result"][u"metadata"][u"globalCounts"][u"count"])
except KeyError:
totals["GooglePlusOne"] = 0
except ValueError:
totals["GooglePlusOne"] = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment