내 트위터 계정을 사용하여 내 응용 프로그램에 로그인하려면 여기를 클릭하십시오.
먼저 twitter 응용 프로그램에 서명하고 https://dev.twitter.com/ 및 응용 프로그램 키, 응용 프로그램 토큰 등을 가져와야합니다. 는 그런 다음 web2py 응용 프로그램에서 db.py 파일을 편집하고 아래의 요건을 충족하는지 확인하세요 : 동일한 파일 추가의 하단에
## create all tables needed by auth if not custom tables
auth_table = db.define_table(
auth.settings.table_user_name,
Field('first_name', length=128, default=""),
Field('last_name', length=128, default=""),
Field('username', length=128, default="", unique=True),
Field('password', 'password', length=256,
readable=False, label='Password'),
Field('registration_id', length=128, default= "",
writable=False, readable=False))
auth_table.username.requires = IS_NOT_IN_DB(db, auth_table.username)
auth.define_tables()
: 전부
# Twitter API
consumer_key = <your key>
consumer_secret = <your secret>
request_token_url = 'https://twitter.com/oauth/request_token'
access_token_url = 'https://twitter.com/oauth/access_token'
authorize_url = 'https://twitter.com/oauth/authorize'
import gluon.contrib.simplejson as json
class TwitterOAuth(OAuthAccount):
def get_user(self):
if self.accessToken() is not None:
client = Client(self.consumer, self.accessToken())
resp, content = client.request('http://api.twitter.com/1/account/verify_credentials.json')
if resp['status'] != '200':
# cannot get user info. should check status
return None
u = json.loads(content)
return dict(username=u['screen_name'], name=u['name'], registration_id=str(u['id']))
auth.settings.login_form=TwitterOAuth(globals(),consumer_key,consumer_secret,
authorize_url, request_token_url, access_token_url)
.
모두가 나에게 잘 작동
건배