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 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据