I'm using the curl php library to get the instagram json feed from a given public profile. I want to use wp_remote_get()
because on the host I'm using for this project, I don't have the ability to use curl to request the json feed, I've noticed that my actual plugin script will work well on localhost, on netsons and aruba but not on tophost.
I don't know if the function included in wordpress will do the same thing so my question is, will wp_remote_get()
return to me the json feed if I provide the instagram url? See the example above:
$feed = wp_remote_get('/?__a=1');
I'm using the curl php library to get the instagram json feed from a given public profile. I want to use wp_remote_get()
because on the host I'm using for this project, I don't have the ability to use curl to request the json feed, I've noticed that my actual plugin script will work well on localhost, on netsons and aruba but not on tophost.
I don't know if the function included in wordpress will do the same thing so my question is, will wp_remote_get()
return to me the json feed if I provide the instagram url? See the example above:
$feed = wp_remote_get('https://www.instagram/profile/?__a=1');
Share
Improve this question
edited Apr 2, 2020 at 18:24
Tom J Nowell♦
61.1k7 gold badges79 silver badges148 bronze badges
asked Apr 1, 2020 at 17:48
sialfasialfa
32910 silver badges29 bronze badges
4
|
1 Answer
Reset to default 0Yes, it will do the same thing.
Taken from the official docs:
/** @var array|WP_Error $response */
$response = wp_remote_get( 'http://www.example/index.html' );
if ( is_array( $response ) && ! is_wp_error( $response ) ) {
$headers = $response['headers']; // array of http header lines
$body = $response['body']; // use the content
}
https://developer.wordpress/reference/functions/wp_remote_get/
Wether it will work for you though, is a different story. If both curl and javascript are returning null
, I don't believe the problem is in the tool used to make the request, but rather what/how you're requesting it.
If your code works everywhere, but does not work on your current host, then you need to speak with your host. Making the same request in a different way is unlikely to help.
curl
is not available on your host, especially with various plugins, i would consider another host if they're unable to provide that PHP extension. Have you tried using thewp_remote_get
code in your question and looking at the result? Keep in mind that a HTTP request is quite an expensive/slow thing to do, if this is to show a carousel or grid you should use javascript instead – Tom J Nowell ♦ Commented Apr 1, 2020 at 18:45$.getJSON
. Withwp_remote_get
I get an array with many key values that I think are the ig page, bun not the images feed in json format – sialfa Commented Apr 2, 2020 at 5:48null
even if you fetch the data via Javascript? Are you sure this is a curl problem?wp_remote_get
doesn't just return the body of the response, it also has the headers etc, did you look at the official docs forwp_remote_get
? They have examples – Tom J Nowell ♦ Commented Apr 2, 2020 at 11:38