Last active
January 4, 2016 11:09
-
-
Save kurap/8613110 to your computer and use it in GitHub Desktop.
Download image from Facebook Profile Picture using Django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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