AttributeError: object 'dict' has no attribute 'read'
I am completely new to python. I am unable to run the following code as it throws an attribute error. Can anyone please help?
import tweepy
import urllib
import json
api_key = "VdG3NjsNKg49NbNb7GMHiX"
api_secret = "yBGKwe2K3QYk5lDny1eIKiyEQawVLQKX1HbRCTRfA9hK9"
access_token_key = "110456973-H8CAAET5CBoEa6FS4CKmk98XOADnJOsxK45"
access_token_secret = "wPUlfaxs1TFrTlXs2VqJIE5ffAfclhJCWmMlLPncb"
auth = tweepy.auth.OAuthHandler(api_key,api_secret)
auth.set_access_token(access_token_key,access_token_secret)
api=tweepy.API(auth,parser=tweepy.parsers.JSONParser())
results=api.search(q="microsoft",count=100)
print type(results)
print json.load(results)
+3
source to share
1 answer
results=api.search(q="microsoft",count=100)
print type(results)
print json.load(results)
results
here already dict
.
There is no need to deserialize it as JSON.
See: tweepy.api.API.search()
which reads:
API.search(q[, lang][, locale][, rpp][, page][, since_id][, geocode][, show_user])
Returns tweets that match a specified query.
Parameters:
q – the search query string
lang – Restricts tweets to the given language, given by an ISO 639-1 code.
locale – Specify the language of the query you are sending. This is intended for language-specific clients and the default should work in the majority of cases.
rpp – The number of tweets to return per page, up to a max of 100.
page – The page number (starting at 1) to return, up to a max of roughly 1500 results (based on rpp * page.
geocode – Returns tweets by users located within a given radius of the given latitude/longitude. The location is preferentially taking from the Geotagging API, but will fall back to their Twitter profile. The parameter value is specified by "latitide,longitude,radius", where radius units must be specified as either "mi" (miles) or "km" (kilometers). Note that you cannot use the near operator via the API to geocode arbitrary locations; however you can use this geocode parameter to search near geocodes directly.
show_user – When true, prepends "<user>:" to the beginning of the tweet. This is useful for readers that do not display Atom’s author field. The default is false.
Return type:
list of SearchResult objects
NB: "Return type:"
+3
source to share