wp_remote_get( $url, $args ) not working?

I’m trying to request data from the virgin giving api to display my fundraising information on my blog. I’m a complete novice and have been unable to workout how such a task would be completed after reading and trying out everything I can find on the topic. This is the code I have been using in a .php file within a wordpress installation on cloud9 (I have removed the search and api key). I have also tried the code on a page on my live blog which is hosted with Bluehost. I’m not sure if I’m creating the page in the correct location or if the below code should be wrapped in some sort of function. Any help that you can provide would be much appreciated.

$url = "https://api.virginmoneygiving.com/fundraisers/v1/";

$args = array(
'headers' => array( "Content-type" => "application/json" ), 
'httpversion' => 1.1,
);

$response = wp_remote_get( $url, $args );

$body = wp_remote_retrieve_body( $response );

$response_code =  wp_remote_retrieve_response_code( $response );

print_r( $response_code  );

echo $response;

Related posts

1 comment

Comments are closed.