can Requests stringify params and append to the URL?
From the WordPress HTTP API (which now uses Requests) i'm trying requests to the YouTube and Vimeo APIs and i'm discovering they will not accept the params as part of the HTTP request object. Parameters must be part of the URL. Is this normal?
Works:
$url = 'https://api.vimeo.com/oauth/authorize/client?grant_type=client_credentials&scope=public%20private';
$auth = base64_encode( $developer_key . ':' . $secret_key );
$headers = array(
'Authorization' => 'Basic ' . $auth,
'Content-Type' => 'application/json'
);
$args = array(
'headers' => $headers
);
$response = wp_remote_post( $url, $args );
Does Not Work:
$url = 'https://api.vimeo.com/oauth/authorize/client';
$auth = base64_encode( $developer_key . ':' . $secret_key );
$data = array(
'grant_type' => 'client_credentials',
'scope' => 'public private'
);
$headers = array(
'Authorization' => 'Basic ' . $auth,
'Content-Type' => 'application/json'
);
$args = array(
'headers' => $headers,
'data' => $data // ('body' doesn't work either)
);
$response = wp_remote_post( $url, $args );
What is even the difference between these two? Doesn't the service's API decode the string to an object anyway?
Is there a way to get Requests to stringify some parameters and append them to the URL?
Wondering this myself
Requests will stringify $data if you're making a GET request, it won't do so for POST/PUT/etc requests. There's been previous discussion of this on #228 (see linked Trac tickets), with a mind towards potentially introducing a new parameter for this.
In the WordPress case, you can build them into the URL yourself:
$url = add_query_arg( array_map( 'urlencode', $args ), $url );