Skip to content

Instantly share code, notes, and snippets.

@kurap
Last active January 4, 2016 11:09
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 kurap/8613110 to your computer and use it in GitHub Desktop.
Save kurap/8613110 to your computer and use it in GitHub Desktop.
Download image from Facebook Profile Picture using Django
FACEBOOK_API_PICTURE_URL = "https://graph.facebook.com/#id#/picture/"
class util_fb:
def __init__(self, access_token=None):
self.access_token = access_token
self.user_agent = PROJECT_NAME + '/' + PROJECT_VERSION
self.error_code = 0
self.message = ""
def get_people_picture(self, fb_id, width=200, height=200):
"""
get_picture
:param self
:param width
:param height
"""
from golfparty.settings import FACEBOOK_API_PICTURE_URL
header = {"User-Agent": self.user_agent}
if not fb_id:
return False
url = FACEBOOK_API_PICTURE_URL.replace('#id#', fb_id) + '?width=' + str(width) + '&height=' + str(height)
req = Request(url=url, headers=header)
try:
res = urlopen(req)
except HTTPError, e:
self.error_code = e.code
self.message = e.reason
return False
except URLError, e:
self.error_code = e.reason
return False
else:
self.response = res.read()
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment