【发布时间】:2019-12-21 09:17:16
【问题描述】:
我正在尝试使用 R 调用 ebay Feed API,但不理解要使用的语法,好像我在调用 API 时缺少标头:
> res <- GET(paste0("https://api.ebay.com/buy/feed/v1_beta/item?feed_scope=ALL_ACTIVE&category_id=625&date=20191216"))
> res
Response [https://api.ebay.com/buy/feed/v1_beta/item?feed_scope=ALL_ACTIVE&category_id=625&date=20191216]
Date: 2019-12-21 08:39
Status: 400
Content-Type: application/json
Size: 228 B
{
"errors" : [ {
"errorId" : 1002,
"domain" : "OAuth",
"category" : "REQUEST",
"message" : "Missing access token",
"longMessage" : "Access token is missing in the Authorization HTTP request header."
}
标题应该在哪里?
我见过这样的事情,添加参数,那会走上正确的道路吗? payload 是不同身份验证元素的列表:
res_bis <- GET("https://api.ebay.com/buy/feed/v1_beta/item?feed_scope=ALL_ACTIVE&category_id=625&date=20191216", authenticate() = payload, encode = "form", verbose())
非常感谢您的帮助!
EDIT1:
我看到了一个关于HTTP headers的信息:
HTTP 请求标头:Content-Type – 必须设置 to:application/x-www-form-urlencoded 授权——“基本”二字 " 后跟您的 Base64 编码的 OAuth 凭据(client_id:client_secret)。
然后我尝试了以下但仍然遇到同样的错误:
GET("https://api.ebay.com/buy/feed/v1_beta/item?feed_scope=ALL_ACTIVE&category_id=625&date=20191216", add_headers("Basic client_id:client_secret"))
EDIT2:在 Andrea 的帮助下更新我的代码:
> GET("https://api.ebay.com/buy/feed/v1_beta/item?feed_scope=ALL_ACTIVE&category_id=625&date=20191216",
+ add_headers(client_id = paste0("Basic", " ",your_token)), content_type("application/x-www-form-urlencoded") )
Response [https://api.ebay.com/buy/feed/v1_beta/item?feed_scope=ALL_ACTIVE&category_id=625&date=20191216]
Date: 2019-12-21 12:17
Status: 400
Content-Type: application/json
Size: 228 B
{
"errors" : [ {
"errorId" : 1002,
"domain" : "OAuth",
"category" : "REQUEST",
"message" : "Missing access token",
"longMessage" : "Access token is missing in the Authorization HTTP request header."
} ]
>
EDIT3:
感谢安德里亚,我设法得到了我的access token:
但是当我这样做时仍然遇到同样的错误:
your_token= "XXXXXXXXX"
GET("https://api.ebay.com/buy/feed/v1_beta/item?feed_scope=ALL_ACTIVE&category_id=625&date=20191216", add_headers(client_id = paste0("Basic", " ",your_token)), content_type("application/x-www-form-urlencoded") )
Response [https://api.ebay.com/buy/feed/v1_beta/item?feed_scope=ALL_ACTIVE&category_id=625&date=20191216]
Date: 2019-12-22 17:56
Status: 400
Content-Type: application/json
Size: 228 B
{
"errors" : [ {
"errorId" : 1002,
"domain" : "OAuth",
"category" : "REQUEST",
"message" : "Missing access token",
"longMessage" : "Access token is missing in the Authorization HTTP request header."
} ]
【问题讨论】:
-
我可能会选择
add_headers()并将令牌作为参数传递给该函数。 -
谢谢,你是对的。让我用更多信息编辑我的帖子。
-
试试
add_headers(content_type("application/x-www-form-urlencoded"), client_id = paste0("Basic", " ",your_token) -
我的错,不能再编辑评论了。
content_type()调用应该放在主要的GET()调用中。 -
别担心,以前去过。试试
GET("https://api.ebay.com/buy/feed/v1_beta/item?feed_scope=ALL_ACTIVE&category_id=625&date=20191216", add_headers(Authorization = paste0("Bearer", " ",your_token)))之类的东西。在 this 这个页面,您可以找到更多关于Authorization标头的信息。