I have a twitter account with an App made, currently it's setup so students can tweet from our website and as such their tweets show "via SchoolAppNameHere" at the bottom of their tweets.
Is it possible to use Twython to use the Appkey and secret key and then get auth tokens from a completely different so when I was to run the bit of code below it would tweet from an account what didn't create the app...
from twython import Twython
APP_KEY = ''
APP_SECRET = ''
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter.update_status(status="test")
Any ideas would be much appreciated :)
Edit, Updated example/explanation below:
Let's say the following image's are from the account "stackoverflowapp" and the app called "Stackoverflow Test App":
Using the following bit of code would tweet from the account "stackoverflowapp" with the tweet "test" via the applicationg called "Stackoverflow Test App"
from twython import Twython
APP_KEY = 'coN_kEY_123456789'
APP_SECRET = 'cOn_sEcr3t_123456789'
OAUTH_TOKEN = 'Acc3ss_tok3N_123456789'
OAUTH_TOKEN_SECRET = 'aCCeSS_tOkEn_sEcrET_123456789'
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter.update_status(status="test")
Let's say that the following image is from the account "useraccount1" and the app is called "testing123":
So now that I have the access tokens to login to the account "useraccount1", how can I tweet via the app called "Stackoverflow test app" which was created by the user: "stackoverflowapp" example of what I tried is below:
from twython import Twython
APP_KEY = 'coN_kEY_123456789'
APP_SECRET = 'cOn_sEcr3t_123456789'
OAUTH_TOKEN = 'Acc3ss_123456789'
OAUTH_TOKEN_SECRET = 'aCCeSS_sEcrET_123456789'
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter.update_status(status="test update")
Unfortunately, I get the error:
TwythonAuthError: Twitter API returned a 401 (Unauthorized), Could not authenticate you
This is of course, possible. When you create an application in Twitter, they give you your own authentication tokens for you to use immediately, as a convenience.
To get keys for other accounts for the same application, you need to request more keys for each account. This is described in detail here: https://dev.twitter.com/docs/auth/obtaining-access-tokens
Since it sounds like you're going to be doing the authorization yourself, the simpler PIN-based approach should probably be used.
You're using
twython
, obtaining these can be done using the library: https://twython.readthedocs.org/en/latest/usage/starting_out.html#authenticationget_authentication_tokens
andget_authorized_tokens
are the methods you're looking for.Store
OAUTH_TOKEN
andOAUTH_TOKEN_SECRET
some place safe and reuse at will. Also, make sure you authorize the correct account when visiting the URL and getting the PIN.All your API calls will be made on bahalf the account that authorized access via the tokens and your
via
line will be your original application. Use the appropriate tokens for each account you'd like to tweet from, it's not possible to mix and match.