在 R 中验证 Brightcove Analytics API
Authenticating Brightcove Analytics API in R
我正在尝试使用 R 对 Brightcove Analytics API (OAuth 2.0) 进行身份验证。我的第一次尝试是使用 httr 包中的 oauth 函数,我尝试按照以下步骤操作
1) 使用 public 和密钥为我的应用程序创建一个变量。完成:
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 不太相似。密钥似乎使用常规身份验证来获取访问令牌:
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 对 Brightcove Analytics API (OAuth 2.0) 进行身份验证。我的第一次尝试是使用 httr 包中的 oauth 函数,我尝试按照以下步骤操作
1) 使用 public 和密钥为我的应用程序创建一个变量。完成:
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 不太相似。密钥似乎使用常规身份验证来获取访问令牌:
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 天免费帐户,里面什么都没有,你应该可以验证代码是否有效。)