python-box:appengine-oauth
差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
python-box:appengine-oauth [2010/11/02 01:27] – @norikae_mapの使用例に車・歩きを追加 dgbadmin | python-box:appengine-oauth [2017/05/13 05:54] (現在) – [その4. TwitterにOAuthでログインしてTwitter APIを使うデモ] dgbadmin | ||
---|---|---|---|
行 44: | 行 44: | ||
=== 使用例 3. 歩きでのルートの案内 === | === 使用例 3. 歩きでのルートの案内 === | ||
- | < | + | < |
- | 試しにつぶやくには、Twitterにログイン後に[[http:// | + | 試しにつぶやくには、Twitterにログイン後に[[http:// |
行 63: | 行 63: | ||
''' | ''' | ||
+ | import json | ||
import logging | import logging | ||
- | import | + | import |
from appengine_twitter import AppEngineTwitter | from appengine_twitter import AppEngineTwitter | ||
from basehandler import BaseHandler, | from basehandler import BaseHandler, | ||
- | from django.utils import simplejson | ||
from google.appengine.ext import db | from google.appengine.ext import db | ||
- | from google.appengine.ext import webapp | ||
行 135: | 行 134: | ||
# ここまで来ればOAuthを使ってAPIが使える。試しにユーザー名を取得 | # ここまで来ればOAuthを使ってAPIが使える。試しにユーザー名を取得 | ||
twitter.verify() | twitter.verify() | ||
- | name = simplejson.loads(twitter.last_response.content)[' | + | name = json.loads(twitter.last_response.content)[' |
self.demo_header() | self.demo_header() | ||
行 176: | 行 175: | ||
routing = [('/ | routing = [('/ | ||
| | ||
- | application = webapp.WSGIApplication(routing, | + | application = webapp2.WSGIApplication(routing, |
- | wsgiref.handlers.CGIHandler().run(application) | + | |
</ | </ | ||
行 196: | 行 194: | ||
__author__ = ' | __author__ = ' | ||
- | __version__ = '0.1.0' | + | __version__ = '0.1.1' |
行 205: | 行 203: | ||
from random import getrandbits | from random import getrandbits | ||
from time import time | from time import time | ||
- | + | ||
class AppEngineOAuth(object): | class AppEngineOAuth(object): | ||
行 220: | 行 218: | ||
else: | else: | ||
self._token_type = ' | self._token_type = ' | ||
- | + | ||
def prepare_login(self, | def prepare_login(self, | ||
行 243: | 行 241: | ||
dic[' | dic[' | ||
| | ||
- | | + | |
return dic | return dic | ||
行 251: | 行 249: | ||
self._token_secret = req_token_secret | self._token_secret = req_token_secret | ||
self._token_type = ' | self._token_type = ' | ||
- | | + | |
params = urllib.urlencode(self.get_oauth_params(acs_token_url, | params = urllib.urlencode(self.get_oauth_params(acs_token_url, | ||
res = urlfetch.fetch(url=acs_token_url, | res = urlfetch.fetch(url=acs_token_url, | ||
行 274: | 行 272: | ||
if self._token_type != None: | if self._token_type != None: | ||
oauth_params[' | oauth_params[' | ||
- | | + | |
# Add other params | # Add other params | ||
params.update(oauth_params) | params.update(oauth_params) | ||
- | | + | |
# Sort and concat | # Sort and concat | ||
s = '' | s = '' | ||
行 283: | 行 281: | ||
s += self._quote(k) + ' | s += self._quote(k) + ' | ||
msg = method + '&' | msg = method + '&' | ||
- | | + | |
# Maybe token_secret is empty | # Maybe token_secret is empty | ||
key = self._secret + '&' | key = self._secret + '&' | ||
- | | + | |
digest = hmac.new(key, | digest = hmac.new(key, | ||
params[' | params[' | ||
行 298: | 行 296: | ||
def _qs2dict(self, | def _qs2dict(self, | ||
- | dic = {} | + | dic = {} |
for param in s.split('&' | for param in s.split('&' | ||
(key, value) = param.split(' | (key, value) = param.split(' |
python-box/appengine-oauth.1288628825.txt.gz · 最終更新: 2010/11/02 01:27 by dgbadmin