【问题标题】:Brightcove API - how to get an access token using requests?Brightcove API - 如何使用请求获取访问令牌?
【发布时间】:2020-04-17 14:10:07
【问题描述】:

Brightcove's API docs说:

授权:基本 {client_id}:{client_secret}

整个 {client_id}:{client_secret} 字符串必须经过 Base64 编码(如果您将其作为 --user 凭据传递,curl 将自动对字符串进行 Base64 编码;在其他语言中,您需要处理 Base64-自己编码)。

这是否意味着我单独对 id 和 secret 进行编码,还是对整个内容进行编码?我仍然不确定我做错了什么。这是我此时的代码:

id_key = b64encode('myid12345qwerty'.encode()).decode("utf-8")
secret_key = b64encode('mysecret12345qwerty67890'.encode()).decode("utf-8")
creds = '{'+id_key+':'+secret_key+'}'
headers = {'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Basic ' + creds}

r = requests.post('https://oauth.brightcove.com/v4/access_token?grant_type=client_credentials', headers = headers)
print(r.status_code)
print(r.text)

这给出了错误,表明它没有获取 client_id 参数。

{"error":"invalid_client","error_description":"The "client_id" parameter is missing, does not name a client registration that is applicable for the requested call, or is not properly authenticated."}

感谢您的指点。

【问题讨论】:

    标签: python api brightcove


    【解决方案1】:

    它将key:secret base 64 编码为单个字符串,但您可以使用 request 对基本身份验证的内置支持并跳过该步骤。

    id_key = 'myid12345qwerty'
    secret_key = 'mysecret12345qwerty67890'
    r = requests.post(
      'https://oauth.brightcove.com/v4/access_token?grant_type=client_credentials',
      auth=(id_key, secret_key)
    )
    

    【讨论】:

      猜你喜欢
      • 2020-04-13
      • 2019-02-19
      • 1970-01-01
      • 2013-10-17
      • 1970-01-01
      • 2012-03-23
      • 2011-04-29
      • 2013-02-17
      • 2021-11-27
      相关资源
      最近更新 更多