我正在尝试get an unauthenticated token from Vimeo's current API v3,以便在我自己的网站上使用它来获取我自己的视频的简单列表。我正在使用WordPress HTTP API函数'wp_remote_post'来生成正确的http请求。
根据Vimeo的说法,这是正确的方法,它是通过POST请求完成的。以下是论点:
HTTP Method: POST
HTTP URL: api.vimeo.com/oauth/authorize/client
HTTP Headers: Authorization: basic, base64_encode( "$client_id: $client_secret" )
Request Body: grant_type=client_credentials&scope=public%20private
并获得
[body] => {"error":"You must provide a valid authenticated access token."}
[raw] => HTTP/1.1 401 Authorization Required
为什么Vimeo在明确的UNauthenticated调用中要求有效的身份验证访问令牌?我已经从我的Vimeo应用程序中提供了实际的客户端ID和客户端密钥,使用Vimeo的指示接收 未经身份验证的访问令牌。我正在从当地环境发送请求。
我检查了类似的问题How to generate Vimeo unauthenticated access token?,并按照其中列出的所有内容进行了操作。没有骰子,我一直试图这样做几个小时。
答案 0 :(得分:0)
Vimeo API似乎只接受参数查询字符串的一部分,而不是HTTP POST对象('body','data'或其他)的一部分。
只有当我将参数直接编码到URL中,而不是将它们作为post对象中的参数传递时,帖子才有效。
使用:
$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 );
不起作用:
$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
);
嗯。 As of WordPress 4.6,WP_HTTP类现在由Ryan McCue构建在Requests上。
所以我的问题似乎也是关于wp_remote_post()如何构造请求的问题。似乎没有办法将参数传递给函数,并将它们在URL中进行字符串化。