sepoto Posted July 25, 2011 Share Posted July 25, 2011 I have this URI that I need to call with PHP: api.tumblr.com/v2/blog/{base-hostname}/info?api_key={key} The URI is returning a JSON object I think. My question is how in PHP do I call the URI and store the result. Once the result is stored I think I can use json_decode(): to decode the result. My version of PHP is 5.3 so I should not have to add any extensions for json functionality from what I have read. Does anyone know how the URI is called from PHP?Thank you. Link to comment Share on other sites More sharing options...
justsomeguy Posted July 25, 2011 Share Posted July 25, 2011 You can use file_get_contents if the URL wrappers are enabled on your server. If file_get_contents won't work on your server over HTTP, then you'll need to use something like the cURL library. Link to comment Share on other sites More sharing options...
thescientist Posted July 26, 2011 Share Posted July 26, 2011 I have this URI that I need to call with PHP:api.tumblr.com/v2/blog/{base-hostname}/info?api_key={key} The URI is returning a JSON object I think. My question is how in PHP do I call the URI and store the result. Once the result is stored I think I can use json_decode(): to decode the result. My version of PHP is 5.3 so I should not have to add any extensions for json functionality from what I have read. Does anyone know how the URI is called from PHP?Thank you. I gave you an example of using cURL here:http://w3schools.invisionzone.com/index.php?showtopic=38968 Link to comment Share on other sites More sharing options...
sepoto Posted July 26, 2011 Author Share Posted July 26, 2011 <?php$limit = 20;$blog_name = 'sepoto.tumblr.com';$use_url = "http://api.tumblr.com/v2/blog/sepoto.tumblr.com/posts?api_key=yourapicodehere";$posts = false;$curl = curl_init($use_url);curl_setopt($curl, CURLOPT_HTTPGET, true);curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);$response = curl_exec($curl);curl_close($curl);$response = json_decode($response, true);if($response['meta']['status'] == 200){$posts = $response['response']['posts'];}unset ($response);print_r($posts);?> Link to comment Share on other sites More sharing options...
Ingolme Posted July 26, 2011 Share Posted July 26, 2011 $use_url = "http://api.tumblr.com/v2/blog/sepoto.tumblr.com/posts?api_key=yourapicodehere";Don't forget to substitute "yourapicodehere" with an actual code. Link to comment Share on other sites More sharing options...
thescientist Posted July 26, 2011 Share Posted July 26, 2011 <?php$limit = 20;$blog_name = 'sepoto.tumblr.com';$use_url = "http://api.tumblr.com/v2/blog/sepoto.tumblr.com/posts?api_key=yourapicodehere";$posts = false;$curl = curl_init($use_url);curl_setopt($curl, CURLOPT_HTTPGET, true);curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);$response = curl_exec($curl);curl_close($curl);$response = json_decode($response, true);if($response['meta']['status'] == 200){$posts = $response['response']['posts'];}unset ($response);print_r($posts);?> so what's the deal? does it work? is it not working? do you make sure to actually put your real api key where I said to make sure your actual API key? what is the output of print_r($posts)? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.