Where would I put my call to wp_remote_get?

I’m guessing I should make a function that: Calls wp_remote_get(“https://jsonplaceholder.typicode.com/todos”) Returns the array of job posting objects Yes, that still leaves the question of where to call it in functions.php, but I’m not sure how I would export it so it would be available in the view. Functions in functions.php are available in templates, making … Read more

Passing cookies when using wp_remote_get

The arguments array for wp_remote_get accepts a cookies parameter: $cookies = []; $cookie = new WP_Http_Cookie( ‘cookie_name’ ); $cookie->name=”cookie_name”; $cookie->value=”your cookie value”; $cookie->expires = 7 * DAY_IN_SECONDS; // expires in 7 days $cookie->path=”https://wordpress.stackexchange.com/”; $cookie->domain = ‘.reddit.com’; $cookies[] = $cookie; $url=”https://tumblr.com/some/url/”; $args = [ ‘cookies’ => $cookies, ]; $response = wp_remote_get( $url, $args );

Strange Situation When Try To Retrieve Github Gist Using wp_remote_get

Do you need the auth to get gists? Get a single gist using the Gist API. $api_url=”https://api.github.com/gists/”; $id = ’63abfe8435d461d30099′; $response = wp_remote_get($api_url . $id); $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); $output = array(); foreach($data[ ‘files’ ] as $file => $fileInfo) { $fR = wp_remote_get($fileInfo[ ‘raw_url’ ]); $fB = wp_remote_retrieve_body($fR); $output[] = $fB; } … Read more

Cannot parse results from wp_remote_get

I can’t’ seem to figure it out, shouldn’t using json_encode allow me to treat the response as a json object? It does allow you to treat it as a JSON object, but that’s useless in PHP. You want the result to be turned from JSON into a PHP array. The required steps are: Make the … Read more

How to convert this cURL to wp_remote_*?

/* ########################################################################## * * * DETERMINE ENTITY, via native wp_remote_post() call * /* ########################################################################## */ function get_entity_type_via_wp( $text_to_analyse, // passed string to be handed to GClouD NLP $entity = ‘type’ // part of each “entities” result to return ) { // Google Cloud API key $options = get_option( ‘cxt_settings’ ); $google_nlp_api = $options[‘cxt_gcloud’]; // Call … Read more

wp_remote_get adding backslashes

wp_remote_get() returns an array containing the response headers and the response body. When you json_encode() the response, which you appear to have done, then the body is going to be escaped so that it doesn’t break the JSON it thinks you’re trying to create. You’re adding the slashes when you do this. To get the … Read more