Skip to content

Instantly share code, notes, and snippets.

@sinsoku
Created July 23, 2010 03:38
Show Gist options
  • Save sinsoku/486974 to your computer and use it in GitHub Desktop.
Save sinsoku/486974 to your computer and use it in GitHub Desktop.
import webbrowser
import tweepy
"""
Query the user for their consumer key/secret
then attempt to fetch a valid access token.
"""
class CacooOAuthHandler(tweepy.OAuthHandler):
def _get_oauth_url(self, endpoint, secure=False):
host = 'cacoo.com'
root = '/oauth/'
prefix = 'https://'
return prefix + host + root + endpoint
def get_authorization_url(self, signin_with_twitter=False):
"""Get the authorization URL to redirect the user"""
try:
# get the request token
self.request_token = self._get_request_token()
# build auth request and return as url
if signin_with_twitter:
url = self._get_oauth_url('authenticate')
else:
url = self._get_oauth_url('authorize')
request = tweepy.oauth.OAuthRequest.from_token_and_callback(
token=self.request_token, http_url=url
)
return request.to_url()
except Exception, e:
raise tweepy.TweepError(e)
if __name__ == "__main__":
consumer_key = raw_input('Consumer key: ').strip()
consumer_secret = raw_input('Consumer secret: ').strip()
auth = CacooOAuthHandler(consumer_key, consumer_secret)
# Open authorization URL in browser
webbrowser.open(auth.get_authorization_url())
# Ask user for verifier pin
pin = raw_input('Verification pin number from cacoo.com: ').strip()
# Get access token
token = auth.get_access_token(verifier=pin)
# Give user the access token
print 'Access token:'
print ' Key: %s' % token.key
print ' Secret: %s' % token.secret
@sinsoku
Copy link
Author

sinsoku commented Jul 23, 2010

Tweepyのgetaccesstoken.pyを元に、Cacoo用にurlを変更しました。

Tree for examples in Tweepy - Gitorious
http://gitorious.org/tweepy/examples/trees/master/oauth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment