Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从GET in R向IDEALITA API发出请求_R_Httr - Fatal编程技术网

无法从GET in R向IDEALITA API发出请求

无法从GET in R向IDEALITA API发出请求,r,httr,R,Httr,我正试图从一个名为“理想主义者”(idealita)的API发出请求 它需要身份验证,所以我接下来要做的是: if(!require("jsonlite")){install.packages("jsonlite")} if(!require("httr")){install.packages("httr")} consumer_key <- "my_key" consumer_secret <- "my_secret" #Use basic auth secret <-

我正试图从一个名为“理想主义者”(idealita)的API发出请求

它需要身份验证,所以我接下来要做的是:

if(!require("jsonlite")){install.packages("jsonlite")}
if(!require("httr")){install.packages("httr")}

consumer_key <- "my_key"
consumer_secret <- "my_secret"

#Use basic auth
secret <- jsonlite::base64_enc(paste(consumer_key, consumer_secret, sep = ":"))
req <- httr::POST("https://api.idealista.com/oauth/token",
                  httr::add_headers(
                    "Authorization" = paste("Basic", gsub("\n", "", secret)),
                    "Content-Type" = "application/x-www-form-urlencoded;charset=UTF-8"
                  ),
                  body = "grant_type=client_credentials"
)


#Extract the access token
token <- paste("Bearer", jsonlite::base64_enc(httr::content(req)$access_token))
if(!require(“jsonlite”){install.packages(“jsonlite”)}
如果(!require(“httr”){install.packages(“httr”)}

consumer_key我在python中发现了一个类似的问题,并在本文中得到了解决

第一部分(身份验证)正常,但第二部分错误。此外,我还尝试了其他url,令牌不需要base64编码

token <- paste("Bearer", httr::content(req)$access_token)

url<-"http://api.idealista.com/3.5/es/search?center=40.42938099999995,-3.7097526269835726&country=es&maxItems=50&numPage=1&distance=452&propertyType=homes&operation=sale"
req <- httr::POST(url, httr::add_headers("Authorization" = token))

token这似乎完全特定于idealista.com API。您可能应该联系他们寻求支持。或者至少提供API文档相关部分的链接。您真的要添加两个授权头吗?
Response [https://api.idealista.com/3.5/es/search?locale=es&maxItems=20&numPage=1&operation=sale&order=publicationDate&propertyType=garages&apikey=80gzxznozajnl3tf30ite86k1p24e4yb&t=1&language=es&bankOffer=true]
  Date: 2017-10-10 15:25
  Status: 400
  Content-Type: text/html
  Size: 4.4 kB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/T...
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es_ES" lang="es_ES">
<head>

                <title>idealista.com : pisos madrid, pisos barcelona, pisos v...
                <meta http-equiv="content-Type" content="text/html; charset=I...
                <meta http-equiv="Expires" content="0"/>
                <meta name="Pragma" content="no-cache"/>
                <meta http-equiv="pragma" content="no-cache"/>
                <meta http-equiv="cache-control" content="no-cache, mustreval...
...
token <- paste("Bearer", httr::content(req)$access_token)

url<-"http://api.idealista.com/3.5/es/search?center=40.42938099999995,-3.7097526269835726&country=es&maxItems=50&numPage=1&distance=452&propertyType=homes&operation=sale"
req <- httr::POST(url, httr::add_headers("Authorization" = token))