Created
July 23, 2010 03:38
-
-
Save sinsoku/486974 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tweepyのgetaccesstoken.pyを元に、Cacoo用にurlを変更しました。
Tree for examples in Tweepy - Gitorious
http://gitorious.org/tweepy/examples/trees/master/oauth