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


Python oauthtwitter.OAuthApi類代碼示例

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


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

示例1: get_profile_from_callback

    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,代碼行數:26,代碼來源:views.py

示例2: callback

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,代碼行數:7,代碼來源:views.py

示例3: oauth_return

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,代碼行數:26,代碼來源:views.py

示例4: generate

    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,代碼行數:33,代碼來源:configuration.py

示例5: _do_finish

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,代碼行數:28,代碼來源:views.py

示例6: oauth_login

def oauth_login(request):
    twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET)
    req_token = twitter.getRequestToken()
    request.session['request_token'] = req_token.to_string()
    signin_url = twitter.getSigninURL(req_token)

    return redirect(signin_url)
開發者ID:jmibanez,項目名稱:DjangoDash,代碼行數:7,代碼來源:views.py

示例7: Callback

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,代碼行數:31,代碼來源:__init__.py

示例8: _do_redirect

def _do_redirect(request):
    oauth = OAuthApi(settings.TWITTER['CONSUMER_KEY'], settings.TWITTER['CONSUMER_SECRET'])
    request_token = oauth.getRequestToken()
    request.session['duration'] = request.POST['duration']
    request.session['twitter_request_token'] = request_token
    authorization_url = oauth.getAuthorizationURL(request_token)
    return redirect(authorization_url)
開發者ID:pombredanne,項目名稱:seeder,代碼行數:7,代碼來源:views.py

示例9: Auth

def Auth(request):
    """docstring for Auth"""
    twitter=OAuthApi(CONSUMER_KEY,CONSUMER_SECRET)
    request_token=twitter.getRequestToken()
    authorization_url=twitter.getAuthorizationURL(request_token)
    request.session['request_token']=request_token
    return HttpResponseRedirect(authorization_url)
開發者ID:fengluo,項目名稱:weblog,代碼行數:7,代碼來源:__init__.py

示例10: get_access_token

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,代碼行數:27,代碼來源:apithreads.py

示例11: finalize_handshake

	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,代碼行數:7,代碼來源:backends.py

示例12: begin_handshake

	def begin_handshake( self, request ):
		twitter = OAuthApi( TWITTER_KEY, TWITTER_SECRET )
		request.session[ 'request_token' ] = twitter.getRequestToken()
		redirect_url = twitter.getAuthorizationURL(request.session[ 'request_token' ] )
		redirect_url = redirect_url[0:redirect_url.find( 'oauth_callback=None' )-2]
		redirect_url = redirect_url.replace( 'http://twitter.com/oauth/authorize', 'http://twitter.com/oauth/authenticate' )
		return HttpResponseRedirect( redirect_url )
開發者ID:johntron,項目名稱:placethings,代碼行數:7,代碼來源:backends.py

示例13: __init__

    def __init__(self, access_token, hrafn_obj):
        OAuthApi.__init__(self, CONSUMER_KEY, CONSUMER_SECRET, access_token)
        self.lock = RLock()

        self.username = self.GetUserInfo().screen_name
        self._username = self.username

        thread = GetUserLists(self, hrafn_obj).start()
開發者ID:annabunches,項目名稱:hrafn,代碼行數:8,代碼來源:apithreads.py

示例14: auth

def auth(request):
    logger = get_fe_logger()
    logger.info('On auth')
    
    if not request.session.has_key('gprofileusername'):
        logger.debug('User doesnt have session on auth(), redirecting to /')
        return HttpResponseRedirect('/')
        
    twitter = OAuthApi(settings.CONSUMER_KEY, settings.CONSUMER_SECRET)
    request_token = twitter.getRequestToken()
    request.session['request_token'] = request_token.to_string()
    authorization_url = twitter.getAuthorizationURL(request_token)
    logger.debug('Sending user to authorization URL %s' % authorization_url)
    return  HttpResponseRedirect(authorization_url)
開發者ID:juanjux,項目名稱:buzz2tweet,代碼行數:14,代碼來源:views.py

示例15: initiate_login

def initiate_login(request):
    if request.method != 'POST':
        r = HttpResponse()
        r.status_code = 405
        return r

    oauth = OAuthApi(
        settings.D51_DJANGO_AUTH['TWITTER']['CONSUMER_KEY'],
        settings.D51_DJANGO_AUTH['TWITTER']['CONSUMER_SECRET']
    )
    request_token = oauth.getRequestToken()
    request.session['twitter_request_token'] = request_token
    
    authorization_url = oauth.getAuthorizationURL(request_token)
    return redirect(authorization_url)
開發者ID:natebunnyfield,項目名稱:d51_django_auth,代碼行數:15,代碼來源:views.py


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