KatPadi's Point

WP and Bearer Token

So here’s some quick stuff regarding a simple function in WP. WP’s wp_remote_request retrieves raw response from the HTTP request.

Goal: To make an HTTP request to a URL and get back the response using Bearer token.

I am writing it down because I had a hard time finding how to do it. All the tuts are all about Basic and Digest authorization.

$BEARER_TOKEN = "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX";
$args = array(
    'headers' => array(
    'Accept-Encoding' => 'gzip',
    'Authorization' => 'Bearer ' . $BEARER_TOKEN) );
$response = wp_remote_request ( URL_HERE, $args );

Just json_decode it or something, if it’s in JSON format.

That’s it. Have fun!

Leave a Reply

Your email address will not be published. Required fields are marked *