本文整理匯總了Python中oauthtwitter.OAuthApi.getRequestToken方法的典型用法代碼示例。如果您正苦於以下問題:Python OAuthApi.getRequestToken方法的具體用法?Python OAuthApi.getRequestToken怎麽用?Python OAuthApi.getRequestToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類oauthtwitter.OAuthApi
的用法示例。
在下文中一共展示了OAuthApi.getRequestToken方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Auth
# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getRequestToken [as 別名]
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)
示例2: _do_redirect
# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getRequestToken [as 別名]
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)
示例3: generate
# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getRequestToken [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()
示例4: get_access_token
# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getRequestToken [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
示例5: oauth_login
# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getRequestToken [as 別名]
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)
示例6: begin_handshake
# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getRequestToken [as 別名]
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 )
示例7: auth
# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getRequestToken [as 別名]
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)
示例8: initiate_login
# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getRequestToken [as 別名]
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)
示例9: initiate_login
# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getRequestToken [as 別名]
def initiate_login(request, redirect_field_name = auth.REDIRECT_FIELD_NAME):
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
request.session['redirect_to'] = request.REQUEST.get(redirect_field_name, '/')
authorization_url = oauth.getAuthorizationURL(request_token)
return redirect(authorization_url)
示例10: get_user_tokens
# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getRequestToken [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]]
示例11: _authorizeBootstrap
# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getRequestToken [as 別名]
def _authorizeBootstrap(self):
"""
"""
oauth_api = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET)
request_token = oauth_api.getRequestToken()
pin = self.guiHandle.requestAuthPin(oauth_api.getAuthorizationURL(request_token))
if (not pin) or (isinstance(pin, str) and not pin.isdigit()):
# I rather do this ugly check than catch this later and have no clue
# of what is causing the erro
raise AuthFail("The retrieved pin is not valid")
self._access_token = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, request_token).getAccessToken(pin)
# Lets write this access token to a filename to reload it next time
# Lets check if directory .tnt exists
directory = os.environ["HOME"] + "/.tnt"
if not (os.path.exists(directory) and os.path.isdir(directory)):
os.mkdir(directory)
file = open(ACCESS_TOKEN_FILENAME, "w")
pickle.dump(self._access_token, file)
file.close()
示例12: setup
# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getRequestToken [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.'
示例13: get
# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getRequestToken [as 別名]
def get(self):
# check session
session = self.get_vaild_session(extend=False)
if session:
self.delete_session(session)
# get request token
twit = OAuthApi()
try:
req_token = twit.getRequestToken()
except DownloadError:
self.redirect_error(msg="twitter is over capacity")
return
# return url control
return_url = urllib.unquote(self.request.get('return_url'))
# insert request token into DB
fetcher.put_req_token(req_token.key, req_token.secret, return_url)
# redirect user to twitter auth page
auth_url = twit.getAuthorizationURL(req_token)
self.redirect(auth_url)
示例14: auth
# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getRequestToken [as 別名]
def auth():
authToken = None
authSecret = None
if os.path.exists('/tmp/twitter.tmp'):
f = open('/tmp/twitter.tmp', 'r')
authToken = f.readline().strip()
authSecret = f.readline().strip()
print "oauth_token: " + authToken
print "oauth_token_secret: " + authSecret
f.close()
needAuth = True
if authToken!=None and authSecret!=None:
twitter = OAuthApi(consumerKey, consumerSecret, authToken, authSecret)
if twitter.autorized():
needAuth = False
if needAuth:
twitter = OAuthApi(consumerKey, consumerSecret)
temp_credentials = twitter.getRequestToken()
print temp_credentials
print twitter.getAuthorizationURL(temp_credentials)
oauth_verifier = raw_input('What is the PIN? ')
access_token = twitter.getAccessToken(temp_credentials, oauth_verifier)
print access_token
print("oauth_token: " + access_token['oauth_token'])
print("oauth_token_secret: " + access_token['oauth_token_secret'])
f = open('/tmp/twitter.tmp', 'w')
f.write('%s\n%s'%(access_token['oauth_token'], access_token['oauth_token_secret']))
f.close()
twitter = OAuthApi(consumerKey, consumerSecret, access_token['oauth_token'], access_token['oauth_token_secret'])
return twitter
示例15: obtainAuth
# 需要導入模塊: from oauthtwitter import OAuthApi [as 別名]
# 或者: from oauthtwitter.OAuthApi import getRequestToken [as 別名]
def obtainAuth(self):
twitter = OAuthApi(self.OAuthConsumerKey, self.OAuthConsumerSecret)
# 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.OAuthUserToken = access_token['oauth_token']
self.OAuthUserTokenSecret = access_token['oauth_token_secret']
print("\n===========================")
print("To prevent this authorization process next session, " +
"add the following lines to the [twitter] section of " +
"your .trackupdaterc:")
print("OAuthUserToken: " + self.OAuthUserToken)
print("OAuthUserTokenSecret: " + self.OAuthUserTokenSecret)
print("===========================\n")