duanpuluan0480 2016-11-03 20:04
浏览 56
已采纳

Vimeo API - 使用WP HTTP API生成未经身份验证的令牌

I'm trying to get an unauthenticated token from Vimeo's current API v3, in order to use it to get a simple list of my own videos on my own website. I'm using a WordPress HTTP API function 'wp_remote_post' to generate a proper http request.

According to Vimeo, this is the correct way to do this and it's done with a POST request. Here are the arguments:

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

enter image description here

and getting

[body] => {"error":"You must provide a valid authenticated access token."}
[raw] => HTTP/1.1 401 Authorization Required

Why is Vimeo asking for a valid authenticated access token on an explicitly UNauthenticated call? I have provided the actual client id and client secret from my Vimeo app, using Vimeo's instructions to receive an unauthenticated access token. I'm sending the request from my local environment.

I have checked the similar question How to generate Vimeo unauthenticated access token? and have followed everything outlined there. No dice, and i've been trying to do this for hours.

  • 写回答

1条回答 默认 最新

  • dongshijiao6890 2016-11-06 07:47
    关注

    Vimeo API seems to only accept the parameters as part of the query string, not as part of the HTTP POST object ('body', 'data', or other).

    Only when I coded the parameters directly into the URL, rather than passing them as parameters in the post object, the post worked.

    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
    );
    

    Hmmm. As of WordPress 4.6, the WP_HTTP class is now built on Requests by Ryan McCue.

    So it seems my question is really also a question about how wp_remote_post() constructs the request. There does not seem to be a way to pass the parameters to the function and have them stringified in the URL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值