How to set User-Agent in python-twitter?

2019-08-30 06:07发布

问题:

i'm writing a small script to tweet messages from the monitoring systems. The only issue i ran into so far is that i can't set the User-Agent correctly, all tweets show up as "from API" which ain't a huge deal but i wonder what I'm doing wrong. An example to reproduce this behavior:

import sys
import twitter

USERNAME="twitteruser"
PASSWORD="twitterpassword"

api = twitter.Api(username=USERNAME, password=PASSWORD)
api.SetUserAgent("Monitor")
api.SetXTwitterHeaders("Monitor", None, "0.1")
status = api.PostUpdate("Test")

I'm running Python 2.6.4 on Ubuntu 9.10 with python-twitter 0.6

Any ideas ? :-)

回答1:

In order to get Twitter to recognize your application you have to use OAuth nowadays and register your application.

See this FAQ entry and Twitter's application registration form.