tags:

views:

165

answers:

3

I want to use the Twitter API in Python to lookup user ids from name using the lookup method. I have done similar requests simply using

response = urllib2.urlopen('http://search.twitter.com...') 

but for this one I need authentication. I don't think I can do it through the Google python twitter API because it doesn't have the lookup method. Any ideas how can I can auth with urllib2??

+3  A: 

You'd probably be better off using one of the actual Python libraries for the Twitter API:

http://dev.twitter.com/pages/libraries#python

Amber
+1  A: 

Use urllib2.Request to define the complete HTTP header:

request = urllib2.Request( 'http://twitter.com/...' )
request.add_header( 'Authorization', 'Basic ' + base64.b64encode( username + ':' + password ) )
response = urllib2.urlopen( request )

Note however that basic authorization will be disabled soon on twitter and you'll need to migrate to OAuth. Twitter API Wiki has some examples on that.

poke
A: 

I'd recommend using the tweepy API.

http://github.com/joshthecoder/tweepy

Examples here: http://github.com/joshthecoder/tweepy-examples

Wasauce