I want to parse json request (GET https://api.twitter.com/1.1/favorites/list.json?count=2&screen_name=episod) using python. please tell me how to do that.
Asked
Active
Viewed 63 times
-1
-
2what specific problem are you facing? This is too broad. – njzk2 Jan 19 '19 at 06:43
-
1https://www.google.com/search?q=python+json – Michael Jan 19 '19 at 06:45
-
Have you looked into python's `requests` library? – Green Cloak Guy Jan 19 '19 at 06:45
-
this should answer your question: https://stackoverflow.com/questions/645312/what-is-the-quickest-way-to-http-get-in-python – Ashu Grover Jan 19 '19 at 06:48
1 Answers
0
You can use requests.get()
to make a GET request to your URL and get the JSON string:
from requests import get
URL = "https://api.twitter.com/1.1/favorites/list.json?count=2&screen_name=episod"
res = get(URL).text
print(res)
# {"errors":[{"code":215,"message":"Bad Authentication data."}]}
print(type(res))
# <class 'str'>
Then you can use json.loads()
to convert the JSON string into a python dictionary:
from json import loads
json_dict = loads(res)
print(json_dict)
# {'errors': [{'code': 215, 'message': 'Bad Authentication data.'}]}
print(type(json_dict))
# <class 'dict'>
Which you can iterate and parse the information you want.

RoadRunner
- 25,803
- 6
- 42
- 75
-
can you please help me with the authentication as I am getting the same error u mentioned. here is the authentication I have used auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access_secret) api = tweepy.API(auth) – nandini banerjee Jan 21 '19 at 06:39