当curl有效时,HTTParty请求中对SlackAPI的Users_not_found

问题描述 投票:0回答:1

我正在尝试使用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
ruby slack-api httparty
1个回答
0
投票

[如果您查看他们的文档,似乎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]" 
    ...

参考:https://api.slack.com/methods/users.lookupByEmail

© www.soinside.com 2019 - 2024. All rights reserved.