當前位置: 首頁>>代碼示例>>Python>>正文


Python OAuthApi.getAccessToken方法代碼示例

本文整理匯總了Python中oauthtwitter.OAuthApi.getAccessToken方法的典型用法代碼示例。如果您正苦於以下問題:Python OAuthApi.getAccessToken方法的具體用法?Python OAuthApi.getAccessToken怎麽用?Python OAuthApi.getAccessToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oauthtwitter.OAuthApi的用法示例。


在下文中一共展示了OAuthApi.getAccessToken方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: callback

# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getAccessToken [as 別名]
def callback(request):
    req_token = oauth.Token.from_string(request.session.get('request_token'))
    api = OAuthApi(settings.CONSUMER_KEY, settings.CONSUMER_SECRET, req_token.key, req_token.secret)
    access_token = api.getAccessToken() 
    request.session["access_token"] = access_token.to_string()
    del request.session["request_token"]
    return HttpResponseRedirect(get_root_path() + "/")
開發者ID:mitnk,項目名稱:mc,代碼行數:9,代碼來源:views.py

示例2: _do_finish

# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getAccessToken [as 別名]
def _do_finish(request):
    # TODO: refactor this out -- should be in a util class or on the model
    # TODO: add check for this, redirect if not found
    try:
        request_token = request.session['twitter_request_token']
        oauth = OAuthApi(settings.TWITTER['CONSUMER_KEY'], settings.TWITTER['CONSUMER_SECRET'], request_token)
        access_token = oauth.getAccessToken()

        twitter = OAuthApi(settings.TWITTER['CONSUMER_KEY'], settings.TWITTER['CONSUMER_SECRET'], access_token)
        user_info = twitter.GetUserInfo()

        default_account = AuthorizedAccount.objects.default_account()

        s = Seeder(
            twitter_id = user_info.id,
            twitter_username = user_info.screen_name,
            authorized_for = default_account
        )
        s.set_expires_on_in_days(request.session['duration'])
        s.save()

        Token.objects.create(
            seeder = s,
            oauth_token = access_token.key,
            oauth_token_secret = access_token.secret
        )
    except HTTPError:
        pass
開發者ID:pombredanne,項目名稱:seeder,代碼行數:30,代碼來源:views.py

示例3: get_profile_from_callback

# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getAccessToken [as 別名]
    def get_profile_from_callback(self, request):
        """Extract the access token and profile details from OAuth callback"""
        request_token = request.session.get('twitter_request_token', None)
        if not request_token: return None

        token = oauth.OAuthToken.from_string(request_token)
        if token.key != request.GET.get('oauth_token', 'no-token'):
            return HttpResponse(status=400)

        twitter = OAuthApi(self.consumer_key, self.consumer_secret, token)
        access_token = twitter.getAccessToken()

        twitter = oauthtwitter.OAuthApi(self.consumer_key, 
                self.consumer_secret, access_token)
        try:
            profile = twitter.GetUserInfo()
        except:
            return None

        return {
            'access_token': access_token.to_string(),
            'id': profile.id,
            'username': profile.screen_name,
            'fullname': profile.name,
            'email': '',
        }
開發者ID:lmorchard,項目名稱:badger,代碼行數:28,代碼來源:views.py

示例4: oauth_return

# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getAccessToken [as 別名]
def oauth_return(request):
    if 'request_token' not in request.session:
        return redirect('dash.views.oauth_login')

    req_token = oauth.OAuthToken.from_string(request.session['request_token'])
    if req_token.key != request.GET.get('oauth_token', 'no-token'):
        del request.session['request_token']
        return redirect('dash.views.oauth_login')

    twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, req_token)
    acc_token = twitter.getAccessToken()

    request.session['access_token'] = acc_token.to_string()
    auth_user = authenticate(access_token=acc_token)

    if auth_user:
        login(request, auth_user)
    else:
        del request.session['access_token']
        del request.session['request_token']
        return HttpResponse("Unable to authenticate you!")

    print "User: %s" % auth_user
    print "request.user: %s" % request.user
    print "is_auth: %s" % request.user.is_authenticated()
    return redirect('dash.views.home')
開發者ID:jmibanez,項目名稱:DjangoDash,代碼行數:28,代碼來源:views.py

示例5: get_access_token

# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getAccessToken [as 別名]
def get_access_token(window):
    auth_api = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET)
    request_token = auth_api.getRequestToken()
    authorization_url = auth_api.getAuthorizationURL(request_token)

    webbrowser.open(authorization_url)
    auth_api = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, request_token)

    dialog = gtk.Dialog("Enter PIN", window, gtk.DIALOG_MODAL, (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
    entry = gtk.Entry()
    dialog.vbox.pack_start(entry)
    entry.show()
    response = dialog.run()
    dialog.hide()
    
    if response == gtk.RESPONSE_OK:
        pin = entry.get_text()

        try:
            access_token = auth_api.getAccessToken(pin)
        except HTTPError:
            access_token = None

        return access_token

    else:
        return None
開發者ID:annabunches,項目名稱:hrafn,代碼行數:29,代碼來源:apithreads.py

示例6: Callback

# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getAccessToken [as 別名]
def Callback(request):
    """docstring for Callback"""
    verifier=request.GET.get('oauth_verifier',None)
    request_token=request.session['request_token']
    twitter=OAuthApi(CONSUMER_KEY,CONSUMER_SECRET,request_token)
    # twitter=OAuthApi(CONSUMER_KEY,CONSUMER_SECRET)
    # access_token=twitter.getAccessToken(request_token,verifier)
    access_token=twitter.getAccessToken()
    # api=t.Api(CONSUMER_KEY,CONSUMER_SECRET,access_token['oauth_token'],access_token['oauth_token_secret'])
    twitter=OAuthApi(CONSUMER_KEY,CONSUMER_SECRET,access_token)
    # user=api.GetUserInfo()
    user=twitter.GetUserInfo()
    twitter_auth=UserMeta(user=request.user,key="oauth",value=1)
    twitter_auth.save()
    # twitter_access_token_key=UserMeta(user=request.user,key="access_token_key",value=access_token['oauth_token'])
    # twitter_access_token_key.save()
    # twitter_access_token_secret=UserMeta(user=request.user,key="access_token_secret",value=access_token['oauth_token_secret'])
    # twitter_access_token_secret.save()
    twitter_access_token_string=UserMeta(user=request.user,key="twitter_access_token_string",value=access_token.to_string())
    twitter_access_token_string.save()
    twitter_id=UserMeta(user=request.user,key="twitter_id",value=user.id)
    twitter_id.save()
    twitter_name=UserMeta(user=request.user,key="twitter_name",value=user.name)
    twitter_name.save()
    twitter_screen_name=UserMeta(user=request.user,key="twitter_screen_name",value=user.screen_name)
    twitter_screen_name.save()
    twitter_description=UserMeta(user=request.user,key="twitter_description",value=user.description)
    twitter_description.save()
    twitter_profile_image_url=UserMeta(user=request.user,key="twitter_profile_image_url",value=user.profile_image_url)
    twitter_profile_image_url.save()
    return HttpResponseRedirect("/setting")
開發者ID:fengluo,項目名稱:weblog,代碼行數:33,代碼來源:__init__.py

示例7: finalize_handshake

# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getAccessToken [as 別名]
	def finalize_handshake( self, request ):
		twitter = OAuthApi( TWITTER_KEY, TWITTER_SECRET, request.session[ 'request_token' ] )
		request.session[ 'access_token' ] = twitter.getAccessToken()
		twitter = OAuthApi( TWITTER_KEY, TWITTER_SECRET, request.session[ 'access_token' ] )
		user_info = twitter.GetUserInfo()
		request.session[ 'twitter_info' ] = user_info
		return request		
開發者ID:johntron,項目名稱:placethings,代碼行數:9,代碼來源:backends.py

示例8: generate

# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getAccessToken [as 別名]
    def generate(self):
        # get the bitly information
        self.getValueFromUser('BITLY_USER', "bit.ly username: ")
        self.getValueFromUser('BITLY_KEY',
                              "api key from 'http://bit.ly/a/account': ")

        # get the twitter information
        from oauthtwitter import OAuthApi
        twitter = OAuthApi(self.__APP_KEY, self.__APP_SECRET)
        temp_creds = twitter.getRequestToken()
        print "visit '%s' and write the pin:" \
            % twitter.getAuthorizationURL(temp_creds)
        oauth_verifier = sys.stdin.readline().strip()
        access_token = twitter.getAccessToken(temp_creds, oauth_verifier)
        config['TWIT_TOKEN'] = access_token['oauth_token']
        config['TWIT_SECRET'] = access_token['oauth_token_secret']

        # get the svn information
        self.getValueFromUser('SVN_FS_ROOT', "Root directory for svn: ",
                              '/svn/')
        self.getValueFromUser('SVN_TRAC_FORMAT',
                              "Format for trac svn urls: ",
                              "http://trac.edgewall.org/changeset/%d")

        # write out the configuration
        handle = open(filename, 'w')
        keys = self.__config__.keys()
        keys.sort()
        for key in keys:
            handle.write("%s='%s'\n" % (key, config[key]))
        handle.write("def normalizeUser(user):\n")
        handle.write("    return user\n")
        pphandle.close()
開發者ID:peterfpeterson,項目名稱:CodeNotifier,代碼行數:35,代碼來源:configuration.py

示例9: get

# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getAccessToken [as 別名]
    def get(self):
        # get req token from DB
        token = self.request.get("oauth_token")
        req_token = fetcher.get_req_token_by_oauth_token(token)
        if not req_token:
            self.redirect('/oauth/twitter/signin')
            return
        
        # model to object
        req_token_obj = oauth.OAuthToken(req_token.token, req_token.secret)
        return_url = req_token.return_url
        
        # get access token
        twit = OAuthApi(access_token=req_token_obj)
        try:
            access_token = twit.getAccessToken()
        except DownloadError:
            self.redirect_error(msg="twitter is over capacity")
            return
            
        token = access_token.key
        secret = access_token.secret
        # delete OAuthToken
        fetcher.delete_req_token_by_model(req_token)
        
        # get user info 
        try:
            twit = OAuthApi(access_token=access_token)
            user = twit.GetUserInfo()
        except DownloadError:
            self.redirect_error(msg="twitter is over capacity")
            return
        

        # add user 
        user_model = fetcher.set_user(twit_id=str(user.id),
                                      twit_name=user.name,
                                      twit_screen_name=user.screen_name,
                                      twit_img_url=user.profile_image_url)
        
        
        # add session
        self.new_session(user_model, token, secret)        
        
        # redirect to home
        if not return_url:
            return_url = '/' 
        self.redirect(return_url)
開發者ID:gochist,項目名稱:Magic-Mirror,代碼行數:50,代碼來源:__init__.py

示例10: get_user_tokens

# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getAccessToken [as 別名]
def get_user_tokens(app_key, app_secret_key):
    if not os.path.isfile("../terminitter.oauth"):  # no user tokens found, create some
        twitter = OAuthApi(app_key, app_secret_key)
        temp_credentials = twitter.getRequestToken()

        print(twitter.getAuthorizationURL(temp_credentials))
        oauth_verifier = raw_input("Go the the URL above, and paste the PIN here: ")
        tokens = twitter.getAccessToken(temp_credentials, oauth_verifier)

        oauthf = open("../terminitter.oauth", "w")
        oauthf.write(tokens["oauth_token"] + "\n" + tokens["oauth_token_secret"])
        oauthf.close()
        return [access_token["oauth_token"], access_token["oauth_token_secret"]]
    else:  # read user tokens from file
        oauthf = open("../terminitter.oauth", "r")
        oauth_tokens = oauthf.read().splitlines()
        return [oauth_tokens[0], oauth_tokens[1]]
開發者ID:jaredbranum,項目名稱:terminitter,代碼行數:19,代碼來源:auth.py

示例11: twitter_return

# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getAccessToken [as 別名]
def twitter_return(request):
    request_token = request.session.get('request_token', None)

    # If there is no request_token for session,
    #    means we didn't redirect user to twitter
    if not request_token:
        # Redirect the user to the login page,
        # So the user can click on the sign-in with twitter button
        return HttpResponse("We didn't redirect you to twitter...")

    token = oauth.OAuthToken.from_string(request_token)

    # If the token from session and token from twitter does not match
    #   means something bad happened to tokens
    if token.key != request.GET.get('oauth_token', 'no-token'):
        del request.session['request_token']
        # Redirect the user to the login page
        return HttpResponse("Something wrong! Tokens do not match...")

    twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, token)
    try:
        fr = twitter.GetFriendsTimeline()
    except HTTPError as e:
        return HttpResponse(str(e))
    access_token = twitter.getAccessToken()
    request.session['access_token'] = access_token.to_string()
    auth_user = authenticate(access_token=access_token)

    # if user is authenticated then login user
    if auth_user:
        login(request, auth_user)
    else:
        # We were not able to authenticate user
        # Redirect to login page
        del request.session['access_token']
        del request.session['request_token']
        return HttpResponse("Unable to authenticate you!")
    # authentication was successful, use is now logged in
#    foo = twitter.GetFollowers()
#    return HttpResponse("You are logged in %s" % twitter.GetFriends())
#    return HttpResponse("You are logged in" + len(foo))
    import string
    return HttpResponse("You are logged in %s" % twitter.GetPublicTimeline())
開發者ID:pombredanne,項目名稱:doubleblind,代碼行數:45,代碼來源:views.py

示例12: OauthAccess

# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getAccessToken [as 別名]
class OauthAccess():
  
    CONSUMER_KEY = settings.TWITTER_CONSUMER_KEY  
    CONSUMER_SECRET = settings.TWITTER_CONSUMER_SECRET  
    ACCESS_TOKEN_URL = settings.TWITTER_ACCESS_TOKEN_URL
  
    mPin = ""
    mOauthRequestToken = ""
    mOauthAccessToken = ""
    mUser = twitter.User
    mTwitterApi = ""
  
    def __init__(self, pOauthRequestToken, pPin):
        self.mOauthRequestToken = pOauthRequestToken
        self.mPin = pPin
  
    def getOauthAccess(self):
        self.mTwitterApi = OAuthApi(self.CONSUMER_KEY, self.CONSUMER_SECRET, self.mOauthRequestToken)
        self.mOauthAccessToken = self.mTwitterApi.getAccessToken(self.mPin)
        self.mAuthenticatedTwitterInstance = OAuthApi(self.CONSUMER_KEY, self.CONSUMER_SECRET, self.mOauthAccessToken)
        self.mUser = self.mAuthenticatedTwitterInstance.GetUserInfo()
開發者ID:nikhiltyagi,項目名稱:sqwag,代碼行數:23,代碼來源:twitterConnect.py

示例13: OauthAccess

# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getAccessToken [as 別名]
class OauthAccess():  
  
    CONSUMER_KEY = "UsGVAZvCxNiZsO7eKkSZzA"  
    CONSUMER_SECRET = "M3lOLh3w9tsgEPG423EhPSkHobGHfinXR2Ju4lxkc"  
    ACCESS_TOKEN_URL = 'https://twitter.com/oauth/access_token'  
  
    mPin = ""  
    mOauthRequestToken = ""  
    mOauthAccessToken = ""  
    mUser = twitter.User  
    mTwitterApi = ""  
  
    def __init__(self, pOauthRequestToken, pPin):  
        self.mOauthRequestToken = pOauthRequestToken  
        self.mPin = pPin  
  
    def getOauthAccess(self):  
        self.mTwitterApi = OAuthApi(self.CONSUMER_KEY, self.CONSUMER_SECRET, self.mOauthRequestToken)  
        self.mOauthAccessToken = self.mTwitterApi.getAccessToken(self.mPin)  
        self.mAuthenticatedTwitterInstance = OAuthApi(self.CONSUMER_KEY, self.CONSUMER_SECRET, self.mOauthAccessToken)  
        self.mUser = self.mAuthenticatedTwitterInstance.GetUserInfo() 
開發者ID:openMinix,項目名稱:Yocto,代碼行數:23,代碼來源:OauthAccess.py

示例14: OauthAccess

# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getAccessToken [as 別名]
class OauthAccess():
 
    CONSUMER_KEY = "atG3B3lZ6fOKshfiUr5FAMDER"
    CONSUMER_SECRET = "zJ52dNaHe3CHDHZahmBC7JwciUS93rFhf5pPzk79CqKZN37R1z"
    ACCESS_TOKEN_URL = 'https://twitter.com/oauth/access_token'
 
    mPin = ""
    mOauthRequestToken = ""
    mOauthAccessToken = ""
    mUser = twitter.User
    mTwitterApi = ""
 
    def __init__(self, pOauthRequestToken, pPin):
        self.mOauthRequestToken = pOauthRequestToken
        self.mPin = pPin
 
    def getOauthAccess(self):
        self.mTwitterApi = OAuthApi(self.CONSUMER_KEY, self.CONSUMER_SECRET, self.mOauthRequestToken)
        self.mOauthAccessToken = self.mTwitterApi.getAccessToken(self.mPin)
        self.mAuthenticatedTwitterInstance = OAuthApi(self.CONSUMER_KEY, self.CONSUMER_SECRET, self.mOauthAccessToken)
        self.mUser = self.mAuthenticatedTwitterInstance.GetUserInfo()
開發者ID:sumit12dec,項目名稱:SentimentFloor,代碼行數:23,代碼來源:OauthAccess.py

示例15: setup

# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getAccessToken [as 別名]
    def setup(self):
        os.system('clear')

        twitter = OAuthApi(self.consumer_key, self.consumer_secret)

        # Get the temporary credentials for our next few calls
        temp_credentials = twitter.getRequestToken()

        # User pastes this into their browser to bring back a pin number
        print(twitter.getAuthorizationURL(temp_credentials))

        # Get the pin # from the user and get our permanent credentials
        oauth_verifier = raw_input('What is the PIN? ')
        access_token = twitter.getAccessToken(temp_credentials, oauth_verifier)

        self.token = access_token['oauth_token']
        self.secret = access_token['oauth_token_secret']

        self.latest = 1
        self.mention = 1

        print 'Clitwi was successfully set up.'
開發者ID:honza,項目名稱:clitwi,代碼行數:24,代碼來源:clitwi.py


注:本文中的oauthtwitter.OAuthApi.getAccessToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。