【发布时间】:2020-03-24 08:19:54
【问题描述】:
我在 R 中遇到了查询 Facebook Graph API 的问题。在以下代码中,我删除了版本、行为和 access_token。如果我将此查询粘贴到 Web 浏览器中,它可以正常工作。
https://graph.facebook.com/vX.X/act_XXXXXXXXXXXXXXXXX/delivery_estimate?access_token= &include_headers=false&method=get&optimization_goal=REACH&pretty=0&suppress_http_code=1&targeting_spec={"age_min":13,"age_max":24,"genders":[1],"flexible_spec":[{"behaviors":[{"id":"6025000826583","name":"Vivieron en Argentina (anteriormente expatriados - Argentina)"}]}],"geo_locations":{"countries":["BR"],"location_types":["home"]},"facebook_positions":["feed","instant_article","instream_video","marketplace"],"device_platforms":["mobile","desktop"],"publisher_platforms":["facebook","messenger"],"messenger_positions":["messenger_home"]}
R 中使用url() 函数的等效查询是:
"https://graph.facebook.com/vX.X/act_XXXXXXXXXXXXXXXXX/delivery_estimate?access_token= &include_headers=false&method=get&optimization_goal=REACH&pretty=0&suppress_http_code=1&targeting_spec={\"age_min\":13,\"age_max\":24,\"genders\":[1],\"flexible_spec\":[{\"behaviors\":[{\"id\":\"6025000826583\",\"name\":\"Vivieron en Argentina (anteriormente expatriados - Argentina)\"}]}],\"geo_locations\":{\"countries\":[\"BR\"],\"location_types\":[\"home\"]},\"facebook_positions\":[\"feed\",\"instant_article\",\"instream_video\",\"marketplace\"],\"device_platforms\":[\"mobile\",\"desktop\"],\"publisher_platforms\":[\"facebook\",\"messenger\"],\"messenger_positions\":[\"messenger_home\"]}"
但是当我的程序在 Linux 中执行时,响应是:
* Trying 31.13.83.8...
* TCP_NODELAY set
* Connected to graph.facebook.com (31.13.83.8) port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* SSL connection using TLSv1.3 / TLS_CHACHA20_POLY1305_SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
* subject: C=US; ST=California; L=Menlo Park; O=Facebook, Inc.; CN=*.facebook.com
* start date: Nov 6 00:00:00 2019 GMT
* expire date: Feb 4 12:00:00 2020 GMT
* subjectAltName: host "graph.facebook.com" matched cert's "*.facebook.com"
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA
* SSL certificate verify ok.
> GET ...
HTTP/1.1
Host: graph.facebook.com
User-Agent: R (3.4.4 x86_64-pc-linux-gnu x86_64 linux-gnu)
Accept: */*
* The requested URL returned error: 400 Bad Request
* stopped the pause stream!
* Closing connection 0
我对这个问题很困惑。
最好的问候, 马丁
【问题讨论】: