I have been using Tweepy for a few weeks now. This is an excellent
project!
The problem that I am running into has to deal with Twitter's Search
API. My application needs to perform searches for hundreds of terms,
so I've written a wrapper that makes no more than N calls per hour
(currently N=100) using Tweepy's Cursor.
I keep running into rate-limit errors after only a few minutes. I
think the problem might have to do with the User-Agent header that I
am passing to the service. I've found a few references to this
online, so I am hoping that it might solve my problem as well.
How can I set a custom User-Agent header using Tweepy? For instance,
given the following example, how can I add the header to the call?
def search(term,sinceid=0,max=1500):
customheader = 'MyApplication v0.16a'
results = tweepy.Cursor(tweepy.api.search, q=term,
since_id=sinceid).items(max)
return results
Thanks for any help!
On Feb 7, 12:11 pm, Josh Roesslein <jroessl...@gmail.com> wrote:
> Hello,
>
> You can provide additional headers with any request by passing a karg named
> "headers".
> Here is an example:
>
> api.get_user('twitter', headers={'User-Agent': 'MyUserAgent'})
>
> That should also work with cursors like this:
>
> Cursor(api.get_user, 'twitter', headers={'User-Agent': 'MyUserAgent'})
>
> Hope that helps you out. Thanks for using Tweepy!
>
> Josh
>
Is there a similar way to add headers to the Streaming class? I've
tried it a couple of ways but I keep getting errors.
For example, in streamwatcher.py, I thought I would be able to do the
following:
stream = tweepy.Stream(username, password, StreamWatcherListener(),
timeout=None, headers={'User-Agent': 'MyUserAgent'})
But I get an unexpected keyword argument error. Can you let me know
what I am doing incorrectly?
Thanks
On Feb 7, 12:11 pm, Josh Roesslein <jroessl...@gmail.com> wrote:
> Hello,
>
> You can provide additional headers with any request by passing a karg named
> "headers".
> Here is an example:
>
> api.get_user('twitter', headers={'User-Agent': 'MyUserAgent'})
>
> That should also work with cursors like this:
>
> Cursor(api.get_user, 'twitter', headers={'User-Agent': 'MyUserAgent'})
>
> Hope that helps you out. Thanks for using Tweepy!
>
> Josh
>