API key and Request library, how to? (Python)

API key and Request library, how to? (Python)

in API Development

Posted by: jelmew.2531

jelmew.2531

Hi all,

Surely there is someone here who knows how to use api keys using the request library in python. I’m trying to expend my own little database. For normal entries, this works (duh):
[spoiler]
def get_jsonparsed_data(url):
#Receive contect as url returned as object"
response=requests.get(url)
return response.json()
[/spoiler]

However, how would one do this using the api key? Googling gives me no clear answer yet, and I’m not that well traversed into the json world.

Greetings,
Jelmew

API key and Request library, how to? (Python)

in API Development

Posted by: Eearslya.6309

Eearslya.6309

The simplest way is to just add the access_token parameter to your URL.
e.g. https://api.guildwars2.com/v2/account?access_token=ABCDEF-1234

Blackgate
Harbinger Tryssa – Revenant

API key and Request library, how to? (Python)

in API Development

Posted by: jelmew.2531

jelmew.2531

If I had known that it was that simple. Thanks a lot.

API key and Request library, how to? (Python)

in API Development

Posted by: zeeZ.5713

zeeZ.5713

From Requests documentation:

def get_jsonparsed_data(url):
   # Receive contect as url returned as object"
   response=requests.get(url, headers={'Authorization': 'Bearer D34D8E3F-...'})
   return response.json()