Esempio n. 1
0
    def get_access_token(self, redirect_uri, code):
        url = "oauth/access_token?%s" % (urlencode({
            'client_id': self.app_id, 'redirect_uri': redirect_uri, 'client_secret': self.app_secret, 'code': code}))
        parsed = urlparse.parse_qs(urlopen(url).read())
        access_token = parsed['access_token']
        if type(access_token) is list or type(access_token) is tuple:
            access_token = access_token[0]

        self.access_token = access_token
        return access_token
Esempio n. 2
0
    def get_access_token_from_short_token(self, short):
        url = "https://graph.facebook.com/oauth/access_token?%s" % \
              (urlencode({'client_id': self.app_id, 'grant_type': 'fb_exchange_token',
                                 'client_secret': self.app_secret, 'fb_exchange_token': short}))
        parsed = urlparse.parse_qs(urlopen(url).read())
        access_token = parsed['access_token']
        if type(access_token) is list or type(access_token) is tuple:
            access_token = access_token[0]

        self.access_token = access_token
        return access_token
Esempio n. 3
0
    def get_access_token_and_expire_timestamp(self, request, redirect_uri):
        if not request.session.has_key('facebook_state'):
            return None, None
        elif request.session['facebook_state'] != request.GET.get('state'):
            return None, None

        url = "https://graph.facebook.com/oauth/access_token?%s" % (urlencode({
            'client_id': self.app_id, 'redirect_uri': redirect_uri, 'client_secret': self.app_secret,
            'code': request.GET.get('code')}))
        parsed = urlparse.parse_qs(urlopen(url).read())
        access_token = parsed['access_token']
        expires = parsed['expires']
        if type(access_token) is list or type(access_token) is tuple:
            access_token = access_token[0]
            expires = expires[0]
        expires = int(expires) + int(time.time())
        self.access_token = access_token
        return access_token, expires