I am trying to get some data from an API (igdb.com/api) but I am having trouble passing authentication.
Since my website is a wordpress website I am using wp_remote_get to retrieve the response from the HTTP request. My PHP code at the moment:
<?php require(dirname(__FILE__) . '/wp-load.php'); $request = wp_remote_get('https://igdbcom-internet-game-database-v1.p.mashape.com/games'); $headers = array(); $headers = 'Accept: application/json'; $headers = 'X-Mashape-Key: myKey'; $body = wp_remote_retrieve_body( $request ); $data_api = json_decode($body, true); var_dump($data_api); ?>
The error I get is “Missing Mashape application key” so I know my code is wrong but can’t figure out how to insert the API key properly. I understand from the API documentation that installing Unirest might facilitate things for me but have no clue how to install this library in wordpress and can’t find any information on this. If someone could tell me wha to change in my code to pass authentication that would be greatly appreciated.
My apologies is this is a dumb question, as this is all new to me.
Read more here: API key in php code