当前位置: 首页>>代码示例>>Python>>正文


Python OAuthToken.from_string方法代码示例

本文整理汇总了Python中oauth.OAuthToken.from_string方法的典型用法代码示例。如果您正苦于以下问题:Python OAuthToken.from_string方法的具体用法?Python OAuthToken.from_string怎么用?Python OAuthToken.from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oauth.OAuthToken的用法示例。


在下文中一共展示了OAuthToken.from_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: exchange_request_token_for_access_token

# 需要导入模块: from oauth import OAuthToken [as 别名]
# 或者: from oauth.OAuthToken import from_string [as 别名]
 def exchange_request_token_for_access_token(self, request_token, verifier):
     parameters = {"oauth_verifier": verifier}
     oauth_request = self.build_oauth_request(
         self.get_access_token_url(), request_token, parameters=parameters
     )
     response = self.execute(oauth_request)
     return OAuthToken.from_string(response)
开发者ID:sunsuk7tp,项目名称:oauthlib,代码行数:9,代码来源:oauth_tools.py

示例2: get_access_token

# 需要导入模块: from oauth import OAuthToken [as 别名]
# 或者: from oauth.OAuthToken import from_string [as 别名]
 def get_access_token(self, request_token):
     url = API_HOME + '/oauth/access_token'
     client = OAuthClient(self.consumer, token=request_token)
     resp, content = client.request(url)
     if resp['status'] != '200':
         raise Exception("Invalid response %s." % resp['status'])
     return OAuthToken.from_string(content)
开发者ID:roymax,项目名称:py-sinaly,代码行数:9,代码来源:__init__.py

示例3: execute_khan_api_method

# 需要导入模块: from oauth import OAuthToken [as 别名]
# 或者: from oauth.OAuthToken import from_string [as 别名]
def execute_khan_api_method(profile_access_token, api_method, cache_timeout=(60 * 60 * 2), 
                            force_refresh=False, return_raw_text=False, user_id=None, 
                            disk_cache=True, cache_per_user=True):
    
    cache_key = ""
    _chosen_cache = get_cache('default')
    if disk_cache:
        _chosen_cache = get_cache('disk')
    
    if cache_per_user:
        if user_id is not None:
            cache_key = "%s^%s^%s" % (user_id, api_method, return_raw_text)
        else:
            cache_key = "%s^%s^%s" % (profile_access_token, api_method, return_raw_text)
    else:
        cache_key = "%s^%s" % (api_method, return_raw_text)
    
    cache_key = cache_key.replace("/","^")
    cache_key = cache_key.replace(".","^")
    cache_key = cache_key.replace(":","^")
    cache_key = cache_key.replace(" ","^")
    
    cache_hit = False
    result_data = _chosen_cache.get(cache_key)
    
    if force_refresh or result_data is None:
        resource = CLIENT.access_api_resource(
            api_method,
            access_token = OAuthToken.from_string(profile_access_token),
            method = "GET"
            )
        
        text = resource['body']
        
        # Error messages can contain HTML. Escape them so they're not rendered.
        is_html = has_text_html_header(resource['headers'])
        if is_html:
            text = cgi.escape(text)
        
        print text
        
        try:
            if return_raw_text:
                result_data = text
            else:
                result_data = simplejson.loads(text)
                
            _chosen_cache.set(cache_key, result_data, cache_timeout)
        except:
            print "exception storing in cache"
        
    else:
        # print "Got json data from cache!"
        cache_hit = True
    
    if not cache_hit:
        # update local tables with fresh data
        print "(cache not hit or is empty: Update local tables with data)"
    
    return result_data
开发者ID:TheKNetwork,项目名称:Codename-K,代码行数:62,代码来源:khan_api.py

示例4: fireeagle

# 需要导入模块: from oauth import OAuthToken [as 别名]
# 或者: from oauth.OAuthToken import from_string [as 别名]
def fireeagle( request ):
    if request.user.fireeagle_token:
        if 'next' in request.session:
            next = request.session['next']
            del request.session['next']
        else:
            next = "/"
        return HttpResponseRedirect( next )

    if not 'oauth_token' in request.GET:
        apptoken = fe.request_token()
        request.session['apptoken'] = apptoken.to_string()
        auth_url = fe.authorize( apptoken )
        if request.session['mobile']:
            auth_url = re.sub(r'https://fireeagle.yahoo.net/', "https://m.fireeagle.yahoo.net/", auth_url)
        logging.info("Redirecting to %s for auth"%auth_url)
        return HttpResponseRedirect( auth_url )

    else:
        apptoken = OAuthToken.from_string( request.session['apptoken'] )
        user_token = fe.access_token( apptoken )
        request.user.fireeagle_token = user_token.to_string()
        request.user.location_from_fireeagle( fe )
        request.user.save()
        if 'next' in request.session:
            next = request.session['next']
            del request.session['next']
        else:
            next = "/"
        return HttpResponseRedirect( next )
开发者ID:tominsam,项目名称:herejustnow,代码行数:32,代码来源:account.py

示例5: exchange_request_token_for_access_token

# 需要导入模块: from oauth import OAuthToken [as 别名]
# 或者: from oauth.OAuthToken import from_string [as 别名]
 def exchange_request_token_for_access_token(self, token):
     oauth_request = OAuthRequest.from_consumer_and_token(self.consumer,
             token=token, http_url=URL_OAUTH_ACCESS_TOKEN)
     oauth_request.sign_request(self.signature_method, self.consumer,
             token)
     resp = self.oauth_fetch(oauth_request, raw=True)
     self.access_token = OAuthToken.from_string(resp) 
     return self.access_token
开发者ID:afternoon,项目名称:followize,代码行数:10,代码来源:twitter.py

示例6: get_request_token

# 需要导入模块: from oauth import OAuthToken [as 别名]
# 或者: from oauth.OAuthToken import from_string [as 别名]
 def get_request_token(self, callback=None):
     url = API_HOME + '/oauth/request_token'
     client = OAuthClient(self.consumer) 
     resp, content =  client.request(url, callback=callback,
                                     force_auth_header=False) 
     if resp['status'] != '200':
         raise Exception("Invalid response %s." % resp['status'])
     return OAuthToken.from_string(content)
开发者ID:roymax,项目名称:py-sinaly,代码行数:10,代码来源:__init__.py

示例7: fetch_request_token

# 需要导入模块: from oauth import OAuthToken [as 别名]
# 或者: from oauth.OAuthToken import from_string [as 别名]
 def fetch_request_token(self, oauth_request):
     # via headers
     # -> OAuthToken
     self.connection.request(oauth_request.http_method, self.request_token_url, headers=oauth_request.to_header())
     response = self.connection.getresponse()
     if response.status != 200:
         raise Exception("Error making request: " + str(response.read()))
     return OAuthToken.from_string(response.read())
开发者ID:swarbhanu,项目名称:ion-ux,代码行数:10,代码来源:OAuthUtilities.py

示例8: is_authenticated

# 需要导入模块: from oauth import OAuthToken [as 别名]
# 或者: from oauth.OAuthToken import from_string [as 别名]
 def is_authenticated(self, access_token):
     if not isinstance(access_token, OAuthToken):
         access_token = OAuthToken.from_string(access_token)
     oauth_request = self.build_oauth_request(self.check_auth_url, access_token)
     response = json.loads(self.execute(oauth_request))
     if "screen_name" in response:
         self.set_access_token(access_token)
         return response["screen_name"]
     return False
开发者ID:sunsuk7tp,项目名称:oauthlib,代码行数:11,代码来源:twitter.py

示例9: get_unauthorized_request_token

# 需要导入模块: from oauth import OAuthToken [as 别名]
# 或者: from oauth.OAuthToken import from_string [as 别名]
 def get_unauthorized_request_token(self, oauth_callback=None):
     parameters = {}
     if oauth_callback:
         parameters = {"oauth_callback": oauth_callback}
     oauth_request = self.build_oauth_request(
         self.get_request_token_url(), parameters = parameters
     )
     response = self.execute(oauth_request)
     return OAuthToken.from_string(response)
开发者ID:sunsuk7tp,项目名称:oauthlib,代码行数:11,代码来源:oauth_tools.py

示例10: fetch_access_token

# 需要导入模块: from oauth import OAuthToken [as 别名]
# 或者: from oauth.OAuthToken import from_string [as 别名]
    def fetch_access_token(self, oauth_request):
        # via headers
        # -> OAuthToken
        self.connection.request(oauth_request.http_method, self.access_token_url, headers=oauth_request.to_header())
        response = self.connection.getresponse()
        if response.status != 200:
            logging.warn("Error temp cred -- response from server:\n" + response.read())
            raise Exception("Error: did not get a temp cred. Response code=" + str(response.status))

        return OAuthToken.from_string(response.read())
开发者ID:swarbhanu,项目名称:ion-ux,代码行数:12,代码来源:OAuthUtilities.py

示例11: fetch_access_token

# 需要导入模块: from oauth import OAuthToken [as 别名]
# 或者: from oauth.OAuthToken import from_string [as 别名]
    def fetch_access_token(self, request_token):

        oauth_request = OAuthRequest.from_consumer_and_token(
            self.consumer, token=request_token, http_url="%s/api/auth/access_token" % self.server_url
        )

        oauth_request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), self.consumer, request_token)

        response = get_response(oauth_request.to_url())

        return OAuthToken.from_string(response)
开发者ID:mwahl,项目名称:analytics,代码行数:13,代码来源:test_oauth_client.py

示例12: return_helper

# 需要导入模块: from oauth import OAuthToken [as 别名]
# 或者: from oauth.OAuthToken import from_string [as 别名]
    def return_helper(self, request, **kwargs):
        from django.http import Http404

        if not "request_token" in request.session:
            raise Http404()
        token = OAuthToken.from_string(request.session["request_token"])
        del request.session["request_token"]
        if token.key != request.GET.get("oauth_token", "no-token"):
            raise Http404()
        verifier = request.GET["oauth_verifier"]
        access_token = self.exchange_request_token_for_access_token(token, verifier)
        request.session["access_token"] = access_token.to_string()
开发者ID:sunsuk7tp,项目名称:oauthlib,代码行数:14,代码来源:twitter.py

示例13: access_token

# 需要导入模块: from oauth import OAuthToken [as 别名]
# 或者: from oauth.OAuthToken import from_string [as 别名]
def access_token():
    try:
        token_string = session['oauth_token_string']
    except KeyError:
        token_string = None

    # Sanity check.
    if not token_string:
        clear_session()
        return None
        
    return OAuthToken.from_string(token_string)
开发者ID:hsingh23,项目名称:khan-api,代码行数:14,代码来源:explorer.py

示例14: auth

# 需要导入模块: from oauth import OAuthToken [as 别名]
# 或者: from oauth.OAuthToken import from_string [as 别名]
    def auth(self, request_token, verifier):
        self.request_token = OAuthToken.from_string(request_token)
        request = OAuthRequest.from_consumer_and_token(
            self.consumer,
            token=self.request_token,
            http_url=self.access_token_url,
            verifier=str(verifier)
        )
        request.sign_request(
            OAuthSignatureMethod_HMAC_SHA1(),
            self.consumer,
            self.request_token
            )

        #if mode == 'header':
        #    resp = urllib2.urlopen(urllib2.Request(url, headers=request.to_header()))
        #else:
        #    resp = urllib2.urlopen(urllib2.Request(request.to_url()))
        resp = urllib2.urlopen(urllib2.Request(request.to_url()))
        string = resp.read()
        access_token = OAuthToken.from_string(string)
        self.access_token = access_token
        self._process_access_token(string)
开发者ID:wayly,项目名称:cnapi,代码行数:25,代码来源:api.py

示例15: access_token

# 需要导入模块: from oauth import OAuthToken [as 别名]
# 或者: from oauth.OAuthToken import from_string [as 别名]
def access_token(session):
    try:
        token_string = session['oauth_token_string']
    except KeyError:
        print 'Got key error'
        token_string = None

    # Sanity check.
    if not token_string:
        print 'Not token string'
        clear_session(session)
        return None
        
    oauth_token = OAuthToken.from_string(token_string)
    print 'Oauth token %s' % oauth_token
    return oauth_token
开发者ID:TheKNetwork,项目名称:Codename-K,代码行数:18,代码来源:khan_api.py


注:本文中的oauth.OAuthToken.from_string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。