0

I think I'm missing something and needed someone to hit me on my head.

import sys
import tweepy
import urllib
import simplejson
from pprint import pprint

CONSUMER_KEY = '----'
CONSUMER_SECRET = '----'
ACCESS_KEY = '----'
ACCESS_SECRET = '----'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)

rate = api.rate_limit_status()
print rate["remaining_hits"]

print api.me().name

search = urllib.urlopen("https://api.twitter.com/1.1/search/tweets.json?q=+arsenal&page=1")

dict = simplejson.loads(search.read())

pprint(dict)

The OAuth works and I'm able to use the tweepy API to return my rate_limit_status and also print my name. I then wanted to use the search API v1.1 (tweepy's api.search() - implements the older search without OAuth) and get a 'Bad Authentication Data' error.

I think my understanding of OAuth is badly incorrect - I'm presuming that once I get an access token I can then make authorized calls. From running the above code I think thats wrong - Could someone help me execute a API1.1 Search using OAuth - what do I need to send with the request?

Thanks!

wholly_cow
  • 907
  • 5
  • 13
  • 20
  • see api.cursor: http://stackoverflow.com/questions/17371652/tweepy-twitter-api-not-returning-all-search-results – Miss.Saturn Nov 23 '14 at 07:01

1 Answers1

0

You don't need to use OAuth for Twitter search. Just call

search = urllib.urlopen("https://search.twitter.com/search.json?q=+arsenal&page=1")

By the way, when you call the Twitter API with urllib.urlopen you're not passing any OAuth credentials, so you will get an error if an endpoint requires authentication. If you look at Tweepy's source code it must be sending the credentials required by Twitter for each call.

Diego Basch
  • 12,764
  • 2
  • 29
  • 24
  • Thanks Diego - I have been using your search call but need some of the newer data that twitter is offering up via the GET search/tweets API1.1. That requires OAuth :( What do I have to use instead of urllib.urlopen to pass OAuth creds? – wholly_cow Dec 31 '12 at 06:21
  • Have you tried tweepi.API.search? http://packages.python.org/tweepy/html/api.html – Diego Basch Dec 31 '12 at 07:26
  • Yes - Even though it isn't specifically documented. APT.search() - just used the non OAuth search. - The documentation says that it returns a 'SearchResult' Object; Thats an object from the non OAuth search. The new search would return 'Status' Objects. – wholly_cow Jan 01 '13 at 00:07