-1

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.

Venkatachalam
  • 16,288
  • 9
  • 49
  • 77

1 Answers1

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