我正在尝试使用httparty gem使用GET请求,以从SlackAPI获取有关特定用户的信息。从卷曲效果很好
curl --data "token=SLACK_TOKEN&[email protected]" https://slack.com/api/users.lookupByEmail
但是下面的代码似乎已损坏,因为我收到了错误{"ok":false,"error":"users_not_found"}
module Slack
class GetUserId
def call
response = HTTParty.get("https://slack.com/api/users.lookupByEmail", payload: payload, headers: headers)
end
def headers
{
'Content-Type' => 'application/json',
'Authorization' => 'Bearer SLACK_TOKEN'
}
end
def payload
{
email: "[email protected]"
}.to_json
end
end
end
[如果您查看他们的文档,似乎API不接受JSON形式,而是“ application / x-www-form-urlencoded。所以像:
headers: {
'Authorization' => 'Bearer SLACK_TOKEN,
"Content-Type" => "application/x-www-form-urlencoded"
},
body: {
"token=SLACK_TOKEN”,
”[email protected]"
...