[英]Curl request in Ruby for Facebook Api
I'm trying to make a curl call with curb gem equivalent to: 我正在尝试用curb gem进行卷曲调用,相当于:
curl \
-F 'name=My new CA' \
-F 'subtype=CUSTOM' \
-F 'description=People who bought from my website' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v2.5/act_<AD_ACCOUNT_ID>/customaudiences
So far my code looks like: 到目前为止我的代码看起来像:
cr = Curl::Easy.http_post("https://graph.facebook.com/v2.5/act_XXXXXXXXXXXXXXX/customaudiences?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") do |curl|
curl.headers['name']='My new CA'
curl.headers['subtype']='CUSTOM'
curl.headers['description']='People who bought from my website'
curl.headers['access_token']='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
end
pp cr.body_str
However, as a response I get this: 但是,作为回应,我得到了这个:
=> "{\"error\":{\"message\":\"(#100) Missing parameter(s): subtype\",\"type\":\"OAuthException\",\"code\":100,\"fbtrace_id\":\"BOd\\/mmhQkkP\"}}"
Could someone explain me what am I doing wrong? 有人能解释一下我做错了什么吗? Thank you!
谢谢!
You can also just use a system call like this: 你也可以使用这样的系统调用:
name = "something"
url = "http://www.example.com"
result = `curl -F 'name=#{name}' #{url}`
result
will hold the output of your system call. result
将保存系统调用的输出。 For more sophisticated http requests, you probably want to take a look at faraday ( https://github.com/lostisland/faraday ) 对于更复杂的http请求,您可能想看一下法拉第( https://github.com/lostisland/faraday )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.