首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Gibbon::MailChimpError (服务器响应状态400 @title=“无效资源”)

Gibbon::MailChimpError (服务器响应状态400 @title=“无效资源”)
EN

Stack Overflow用户
提问于 2016-03-21 15:10:50
回答 2查看 1.1K关注 0票数 0

我试图使用吉本宝石和跟踪他们的github文档。这是我的代码

代码语言:javascript
运行
复制
class ChimpController < ApplicationController
  def create
    send_to_mail_chimp ( params[:email])
  end

  def send_to_mail_chimp(email)
    puts "send email is #{email}"
    gibbon = Gibbon::Request.new(api_key: "bla")
    gibbon.timeout = 10
    gibbon.lists('e61cf2454d').members.create(body: {email_address: email, status: "subscribed"})
  end
end

<%= simple_form_for :email, url: newsletter_path, :method => :post do |f| %> <%= f.input :email, input_html: {class: 'form-control', placeholder: 'enter email'} %> <% end %>

准确的错误信息是

代码语言:javascript
运行
复制
Gibbon::MailChimpError (the server responded with status 400 @title="Invalid Resource", @detail="The resource submitted could not be validated. For field-specific details, see the 'errors' array.", @body={"type"=>"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/", "title"=>"Invalid Resource", "status"=>400, "detail"=>"The resource submitted could not be validated. For field-specific details, see the 'errors' array.", "instance"=>"", "errors"=>[{"field"=>"email_address", "message"=>"Schema describes string, object found instead"}]}, @raw_body="{\"type\":\"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/\",\"title\":\"Invalid Resource\",\"status\":400,\"detail\":\"The resource submitted could not be validated. For field-specific details, see the 'errors' array.\",\"instance\":\"\",\"errors\":[{\"field\":\"email_address\",\"message\":\"Schema describes string, object found instead\"}]}", @status_code=400):
  app/controllers/chimp_controller.rb:10:in `send_to_mail_chimp'
  app/controllers/chimp_controller.rb:3:in `create'
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-03-21 16:05:21

您要返回的错误消息正是告诉您问题所在:

代码语言:javascript
运行
复制
{
    "field": "email_address",
    "message": "Schema describes string, object found instead"
}

您将电子邮件作为javascript对象(ruby散列)传入,而不是字符串。您需要传递的只是原始的电子邮件地址。

票数 2
EN

Stack Overflow用户

发布于 2016-03-21 15:48:45

我认为您需要为members方法提供小写电子邮件地址(通过mailchimp用户管理)的MD5哈希。试一试

代码语言:javascript
运行
复制
def send_to_mail_chimp(email)
  puts "send email is #{email}"
  gibbon = Gibbon::Request.new(api_key: "bla")
  gibbon.timeout = 10
  md5_email = Digest::MD5.hexdigest(email['email'].downcase)
  # I prefer 'upsert' to 'create' but should work with either
  gibbon.lists('e61cf2454d').members(md5_email).upsert(body: {email_address: email['email'], status: "subscribed"})
end
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36134771

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档