2014-07-21 7 views
1

R (httr)에서 QPX Exprss (Google)를 쿼리하려고하지만 어떤 이유로 든 0 결과가 표시됩니다. 이것은 내 쿼리입니다 :QPX Express에서 R

x <- list(
    request = list(
     slice = list(c(origin = "BOS", destination = "LAX", date = "2014-07-29")), 
     passengers = c(adultCount = 1, infantInLapCount = 0, infantInSeatCount = 0, 
        childCount = 0, seniorCount = 0), 
     solutions = 10, 
     refundable = "false") 
    ) 

그리고 이것은 명령입니다 : 마지막으로

POST("https://www.googleapis.com/qpxExpress/v1/trips/search?key=MY_KEY", 
    body = toJSON(x), add_headers("Content-Type" = "application/json"), verbose(), 
    add_headers(Expect = "")) 

, 구글로부터의 응답 :

* About to connect() to www.googleapis.com port 443 (#0) 
* Trying 173.194.66.95... * connected 
* Connected to www.googleapis.com (173.194.66.95) port 443 (#0) 
* successfully set certificate verify locations: 
* CAfile: C:/Users/XXXX/Documents/R/win-library/3.1/httr/cacert.pem 
    CApath: none 
* SSL re-using session ID 
* SSL connection using ECDHE-RSA-RC4-SHA 
* Server certificate: 
* subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.googleapis.com 
* start date: 2014-07-02 13:35:47 GMT 
* expire date: 2014-09-30 00:00:00 GMT 
* subjectAltName: www.googleapis.com matched 
* issuer: C=US; O=Google Inc; CN=Google Internet Authority G2 
* SSL certificate verify ok. 
> POST /qpxExpress/v1/trips/search?key=MY_KEY HTTP/1.1 
Host: www.googleapis.com 
Accept: */* 
Accept-Encoding: gzip 
user-agent: curl/7.19.6 Rcurl/1.95.4.1 httr/0.3 
Content-Type: application/json 
Content-Length: 220 

< HTTP/1.1 200 OK 
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate 
< Pragma: no-cache 
< Expires: Fri, 01 Jan 1990 00:00:00 GMT 
< Date: Mon, 21 Jul 2014 10:39:46 GMT 
< ETag: "FHaaT3rgbj6tTc1zJmPkVQ6bD-8/wa9h__cUdEwRE2bp0yW5NTA6fec" 
< Content-Type: application/json; charset=UTF-8 
< Content-Encoding: gzip 
< X-Content-Type-Options: nosniff 
< X-Frame-Options: SAMEORIGIN 
< X-XSS-Protection: 1; mode=block 
< Server: GSE 
< Alternate-Protocol: 443:quic 
< Transfer-Encoding: chunked 
< 
* Connection #0 to host www.googleapis.com left intact 
Response [https://www.googleapis.com/qpxExpress/v1/trips/search?key=MY_KEY] 
    Status: 200 
    Content-type: application/json; charset=UTF-8 
{ 
"kind": "qpxExpress#tripsSearch", 
"trips": { 
    "kind": "qpxexpress#tripOptions", 
    "requestId": "UTlu4NDcLz3Ypcicp0KKI3", 
    "data": { 
    "kind": "qpxexpress#data", 
    "airport": [ 
    { 
    "kind": "qpxexpress#airportData", ... 

이 사람이 어떤 행운이 있었나요?

감사합니다.

카를로스

답변

2

누군가가 관심이있는 경우. 다음은 던컨과 해들리에서 답을 다음과 같습니다

다음과 같이 윈도우에서 postForm 명령은 다음과 같습니다

library(RCurl) 
library(RJSONIO) 

x <- list(
     request = list(
     passengers = list(
      adultCount = 1 
     ), 
     slice = list(
      list(
      origin = "BOS", 
      destination = "LAX", 
      date = "2014-07-29" 
     ) 
     ), 
     refundable = "false", 
     solutions = 10 
    ) 
    ) 

postForm("https://www.googleapis.com/qpxExpress/v1/trips/search?key=my_KEY", 
     .opts = list(postfields = toJSON(x), 
         cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"), 
         httpheader = c('Content-Type' = 'application/json', 
            Accept = 'application/json'), 
         verbose = TRUE 
       )) 

당신이 리눅스 머신에서 실행하는 경우가

cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl") 

를 생략 할 수 있습니다.

library(httr) 

url <- "https://www.googleapis.com/qpxExpress/v1/trips/search" 
json <- jsonlite::toJSON(x, auto_unbox = TRUE) 

POST(url, query = list(key = my_Key), body = json, content_type_json()) 

환호 : 당신은 오히려 HTTR 사용하는 경우

은 여기 명령입니다.

카를로스