tjfrahme tjfrahme - 4 months ago 143
Python Question

Pulling Data from App Annie API - Python

I need to pull some data from App Annie's API using Python. However I am unable to connect. I double checked my API key and the "documentation". Does anyone know how I can connect through their API? I keep getting a 401 unauthorized access error.

https://support.appannie.com/hc/en-us/articles/204208864-3-Authentication

import json
import requests

url = 'https://api.appannie.com/v1.2/apps/ios/app/12345678/reviews?start_date=2012-01-01&end_date=2012-02-01&countries=US'
key = 'Authorization: bearer b7e26.........'

response = requests.get(url, key) #After running up to this I get 401

data = json.loads(response.json()) #data is a dictionary

Answer

You need to specify your api key in the HTTP header:

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