2

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.com/profile/?__a=1');

4
  • You may run into issues if 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 the wp_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
    Apr 1, 2020 at 18:45
  • I've checked. the curl extension is available but return null, the same will happen if I use $.getJSON. With wp_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
    Apr 2, 2020 at 5:48
  • So you get null 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 for wp_remote_get? They have examples
    – Tom J Nowell
    Apr 2, 2020 at 11:38

1 Answer 1

0

Yes, it will do the same thing.

Taken from the official docs:

/** @var array|WP_Error $response */
$response = wp_remote_get( 'http://www.example.com/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.org/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.

6
  • The url I'm using for the get request will return a json with the link of the media of evry public feed. The strange things is that only on that hos I can't get a response from the url. You can test the url to see the response, I'm not dealing directly with the api, this to avoid my clients to connect their account to see the feed.
    – sialfa
    Apr 2, 2020 at 17:06
  • "only on that hos" <- I don't know what this means, can you rephrase it? If you're having trouble with the Instagram API you need to ask their support or people familiar with it. This isn't instagram stack exchange :/ We can't help you setup Instagram API use
    – Tom J Nowell
    Apr 2, 2020 at 17:13
  • it's a typo, I mean host for hosting provider! I'm not using the API ! I'm just using curl and I want to replace it with a native wordpress function like wp_remote_get to have the json feed
    – sialfa
    Apr 2, 2020 at 17:14
  • If your problem is host specific then you need to speak with your host. Changing it to WP is unlikely to make a difference if your existing code works elsewhere
    – Tom J Nowell
    Apr 2, 2020 at 18:23
  • Yes, this is what I asked for, if the json returned can be retrived also using the wp_remote_get to replace the curl native php library. The strange is the response I get with wp_remote_get, It will only show the number of char in the body, but not the body also if I access to the ['body'] array key.
    – sialfa
    Apr 2, 2020 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.