如何使用 OAuth 和 OAuth 聚合帐户网络2py?

发布于 2024-12-22 01:46:50 字数 370 浏览 2 评论 0原文

Tumblr 提供了一个非常简单的界面来链接您的 Twitter 和 Facebook 帐户,以便通过他们的服务发布内容。我想在我的应用程序中做类似的事情 - 为人们提供一个点来聚合不同的帐户,如 Flickr、Facebook、Twitter 等 - 而且我不想每年为 Janrain 的帐户映射花费 1,000 美元 这样做。

如何使用 web2py 聚合多个帐户? 我感觉应该 从这里开始,但希望有更具体的教程或最佳实践记录。

Tumblr provides a very simple interface to link your Twitter and Facebook accounts for posting through their service. I'd like to do something similar in my application - provide a single point for people to aggregate different accounts like Flickr, Facebook, Twitter, etc. - and I don't want to spend $1,000 per year for Janrain's Account Mapping to do so.

How do I link multiple accounts in aggregate using web2py? I have a feeling I should start here, but was hoping there were more concrete tutorials or best practices documented.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒的傷心 2024-12-29 01:46:50

这是我正在做的事情,以便使用我的 Twitter 帐户登录我的应用程序。

首先,您需要在此处注册 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)

就这样。

一切对我来说都很好

干杯

here what I'm doing in order to use my twitter account to login to my application.

First of all you need to sign for a twitter application here and get https://dev.twitter.com/
and the application key, application token and so forth.
Then edit in your web2py application the db.py file and make sure you have the following:

## 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()

at the bottom of the same file add:

#  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)

That's all.

Everything worked fine to me

Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文