Hatena::Grouptopcoder

naoya_t@topcoder RSSフィード

2010-08-23

2-legged OAuth

15:03 |  2-legged OAuth - naoya_t@topcoder を含むブックマーク はてなブックマーク -  2-legged OAuth - naoya_t@topcoder  2-legged OAuth - naoya_t@topcoder のブックマークコメント

import httplib,urllib,urllib2
import oauth
 
url = "http://gdd-2010-quiz-japan.appspot.com/oauth/########################"

params = { 'hello': 'world' }

consumer_key = '########################'
secret_key   = '########################'
 
consumer = oauth.OAuthConsumer(consumer_key, secret_key)

request  = oauth.OAuthRequest.from_consumer_and_token(consumer, http_method='POST', http_url=url, parameters=params)
request.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(), consumer, None)

print request.to_url()
print request.to_header()

conn = httplib.HTTPConnection("gdd-2010-quiz-japan.appspot.com")
conn.request("POST", "/oauth/########################", urllib.urlencode(params), request.to_header('devquiz'))
response = conn.getresponse()
print response.status, response.reason
data = response.read()
conn.close()
print data
トラックバック - https://topcoder-g-hatena-ne-jp.jag-icpc.org/n4_t/20100823