Search code examples
pythonjsonappannie

Automate data pull from App Annie API issue


I am needing to automate a daily pull of app Annie data reviews and land them in S3. With the below I am trying to see if I can just pull one days worth of data but am getting an error 'TypeError: expected string or buffer'. I am new to python, can someone explain what I am doing wrong or another way to accomplish what I am trying to do?

import json
import requests

url = 'https://api.appannie.com/v1.2/apps/ios/app/331177714/reviews?       
start_date=2016-1-01&end_date=2016-6-26&countries=US'
key = 'Authorization: bearer 585e46.....'

response = requests.get(url, 
                        headers = {'Authorization':'bearer 585e46.....'})   

data = json.loads(response.json()) 

Solution

  • .json method you're using comes from requests object and it already converts string to proper json. So you can do two things

    1. Convert to json with requests object method: data = response.json()

    2. Get text from your response and turn into json with Python json lib: data = json.loads(response.text)