How to switch from Twitter API single account use to multiaccount use, keeping it still a private app?

爱⌒轻易说出口 提交于 2019-12-12 02:17:33

问题


I've made an app that posts to a Twitter account of mine. Currently I have hard-coded into the system the consumer key, consumer secret, access token key and access token secret.

Now I would like to use this app for two accounts and perhaps later even more. Which values have to be changed to make the same app post into the other account and how to get the values? I can see none of them in dev.twitter.com.


回答1:


The python-twitter package is probably going to be what you want here.

the way you should set this up is in settings.py put

TWITTER_ACCOUNTS = {
    'public': {
        'consumer_key':        'PUT_C_KEY_HERE',
        'consumer_secret':     'PUT_C_SEC_HERE',
        'access_token_key':    'PUT_A_KEY_HERE',
        'access_token_secret': 'PUT_A_SEC_HERE',
     },
     'personal': {
        'consumer_key':        'PUT_C_KEY_HERE',
        'consumer_secret':     'PUT_C_SEC_HERE',
        'access_token_key':    'PUT_A_KEY_HERE',
        'access_token_secret': 'PUT_A_SEC_HERE',
     },
}

from twitter api page:

For applications with single-user use cases, we now offer the ability to issue an access token for your own account (and your own applications). You can generate these keys from your application details pages.

go to https://dev.twitter.com/apps to get your keys

Then in your code when doing your initialisation, (e.g. for personal account) put

import twitter
from django.conf import settings

account = settings.TWITTER_ACCOUNTS['personal']
api = twitter.Api(**account)  # <----This will inject your account settings as keyword args
status = api.PostUpdate('I love python-twitter!')

Hope this helps you.

EDIT: To register your second account with the application, Follow these instructions from Step 3: http://jeffmiller.github.com/2010/05/31/twitter-from-the-command-line-in-python-using-oauth



来源:https://stackoverflow.com/questions/5445709/how-to-switch-from-twitter-api-single-account-use-to-multiaccount-use-keeping-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!