使用http请求从r查询yelp-签名无效
我正试图通过HTTP请求从R中查询Yelp。我在获取使用http请求从r查询yelp-签名无效,r,oauth,R,Oauth,我正试图通过HTTP请求从R中查询Yelp。我在获取oauth\u签名参数以匹配Yelp期望的内容时遇到问题 这是到目前为止我的代码 YWSID <- "..." CONSUMER_KEY <- "..." CONSUMER_SECRET <- "..." TOKEN <- "..." TOKEN_SECRET <- "..." yelp_bus <- function(rest, ywsid, cons_key, cons_sec, tok, tok_se
oauth\u签名
参数以匹配Yelp期望的内容时遇到问题
这是到目前为止我的代码
YWSID <- "..."
CONSUMER_KEY <- "..."
CONSUMER_SECRET <- "..."
TOKEN <- "..."
TOKEN_SECRET <- "..."
yelp_bus <- function(rest, ywsid, cons_key, cons_sec, tok, tok_sec) {
require(package = "digest")
require(package = "rjson")
require(package = "RCurl")
require(package = "stringr")
rest1 <- gsub(pattern = " ", replacement = "%2520", x = rest)
rest2 <- gsub(pattern = " ", replacement = "+", x = rest)
nonce <- paste(sample(x = c(0:9, letters, LETTERS, "_"), size = 32, replace = TRUE), collapse = "")
tm <- format(x = Sys.time(), "%s")
api_url <- paste("GET\u0026http%3A%2F%2Fapi.yelp.com%2Fv2%2Fsearch\u0026",
"limit%3D1%26location%3DChicago%2520IL%26",
"oauth_consumer_key%3D", cons_key, "%26",
"oauth_nonce%3D", nonce, "%26",
"oauth_signature_method%3DHMAC-SHA1%26",
"oauth_timestamp%3D", tm, "%26",
"oauth_token%3D", tok, "%26",
"term%3D", rest1,
sep = "")
signature <- hmac(key = tok_sec, object = api_url, algo = "sha1")
api_url <- paste("http://api.yelp.com/v2/search?",
"limit=1&location=Chicago+IL&",
"oauth_consumer_key=", cons_key, "&",
"oauth_nonce=", nonce, "&",
"oauth_signature=", signature, "&",
"oauth_signature_method=HMAC-SHA1&",
"oauth_timestamp=", tm, "&",
"oauth_token=", tok, "&",
"term=", rest2,
sep = "")
return(api_url)
}
yelp_bus(rest = "chez moi",
ywsid = YWSID,
cons_key = CONSUMER_KEY,
cons_sec = CONSUMER_SECRET,
tok = TOKEN,
tok_sec = TOKEN_SECRET)
按如下方式创建签名:
signature <- as.character(curlPercentEncode(base64(hmac(key=paste(cons_sec, tok_sec, sep="&"), object=api_url, algo="sha1", serialize=FALSE, raw=TRUE))))
签名您是否将错误消息中的描述与本地生成的描述进行了比较?它们应该是相同的。@John当我在散列之前打印api\u url
时,“\u0026”变成了一个符号。所以我猜这是我的问题。有没有办法让课文保持原样?
signature <- as.character(curlPercentEncode(base64(hmac(key=paste(cons_sec, tok_sec, sep="&"), object=api_url, algo="sha1", serialize=FALSE, raw=TRUE))))