gpt4 book ai didi

r - 在 R 中验证 Brightcove Analytics API

转载 作者:行者123 更新时间:2023-12-01 23:31:09 24 4
gpt4 key购买 nike

我正在尝试验证 Brightcove Analytics API (OAuth 2.0) with R。我的第一次尝试是在 httr 包中使用 oauth 函数,我尝试按照这些步骤操作

1) 使用公钥和私钥为我的应用程序创建一个变量。完成:

library("httr")
myapp <- oauth_app("MyBrightcoveApp", key="mykeyhere", secret = "mysecrethere")

2) 找到 Brightcove 的 OAuth 设置。 oauth_endpoint() 函数需要一个访问 URL,我找到了“https://oauth.brightcove.com/v3/access_token”,还有一个我没有找到的授权 URL。我不确定 Brightcove 是否允许浏览器内帐户身份验证。

我的下一次尝试是使用 httr::POST() 函数。我查看了 Brightcove 的示例 node.js 代码:

var request = require('request');
var client_id = "{your_client_id}";
var client_secret = "{your_client_secret}";
var auth_string = new Buffer(client_id + ":" + client_secret).toString('base64');
console.log(auth_string);
request({
method: 'POST',
url: 'https://oauth.brightcove.com/v3/access_token',
headers: {
'Authorization': 'Basic ' + auth_string,
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'grant_type=client_credentials'
}, function (error, response, body) {
console.log('Status: ', response.statusCode);
console.log('Headers: ', JSON.stringify(response.headers));
console.log('Response: ', body);
console.log('Error: ', error);
});

我正在尝试将其翻译成 R。我从以下内容开始:

library(httr)
client_id <- "myClientIDhere"
client_secret <- "mySecretHere"
auth_string <- paste0(client_id, ":", client_secret)

但我似乎无法在我的 POST 请求中获取必要的数据。

myresponse <- POST(myrequest, username=auth_string, httpheader='Content-type: application/x-www-form-urlencoded', body = 'grant_type=client_credentials'  )

将 myresponse$request$auth_token 显示为 NULL。也是如此

myresponse <- POST(myrequest, authenticate(client_id, client_secret), httpheader='Content-type: application/x-www-form-urlencoded', body = 'grant_type=client_credentials'  )

知道我可能遗漏了什么吗?

最佳答案

这是一个非常奇怪的身份验证系统,与 OAuth 不太相似。 key 似乎使用常规身份验证来获取访问 token :

library(httr)

id <- "ee6fb53d-6e0d-40f4-84f9-dc043f6f3399"
secret <- "a33sgCuU_WLFm89oBcgl0FCpdLZhtsbHIunNLJWVBwiir5MCGPinHoORvSw4YnwjURZuZa2b-NGFBNqUvevv3w"

r <- POST("https://oauth.brightcove.com/v3/access_token",
body = list(grant_type = "client_credentials"),
authenticate(id, secret),
encode = "form"
)
stop_for_status(r)
token <- content(r)$access_token

(那个 id 和 secret 是我的 30 天免费帐户,里面什么都没有,应该允许你验证代码是否有效。)

关于r - 在 R 中验证 Brightcove Analytics API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35468215/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com