最近几天我一直在为这个问题挠头,所以我希望有人能帮助我,因为我不知道在哪里挖掘。正如标题所说,我正在使用omniauth google oauth2进行身份验证的项目。这部分从一开始就工作正常。下一部分是在 google 联系人 api 中创建联系人,但它不起作用。
由于要生成的 xml/atom 有点重,我决定使用 xml 视图并使用 render_to_string 在我的控制器中检索它。因为我对rails不太了解,所以我只是认为这样生成会更干净。这工作正常。
所以这是我的 oauth2 调用:
strxml = render_to_string( :partial => 'createInGoogle', :layout => false )
response = access_token.post('/m8/feeds/contacts/default/full', params: {:body => strxml, :header => 'Content-type: application/atom+xml;GData-Version: 3.0'})
当我调试该调用时,我可以看到生成的 url 看起来像
"https://www.google.com/m8/feeds/contacts/default/full?body=%3Catom%3Aentry+xmlns%3Aatom%3D%27http%3A%2F%2Fwww.w3.org%2F2005%2FAtom%27+xmlns%3Agd%3D%27http%3A%2F%2Fschemas.google.com%2Fg%2F2005%27%3E%0A%3Catom%3Acategory+scheme%3D%27http%3A%2F%2Fschemas.google.com%2Fg%2F2005%23kind%27+term%3D%27http%3A%2F%2Fschemas.google.com%2Fcontact%2F2008%23contact%27%2F%3E%0A%3Cgd%3Aname%3E%0A%3Cgd%3AgivenName%3EPhilippe+Henri+Raymond%3C%2Fgd%3AgivenName%3E%0A%3Cgd%3AfamilyName%3EMichel+%3C%2Fgd%3AfamilyName%3E%0A%3Cgd%3AfullName%3EPhilippe+Henri+Raymond+Michel+%3C%2Fgd%3AfullName%3E%0A%3C%2Fgd%3Aname%3E%0A%3Catom%3Acontent+type%3D%27text%27%3ENotes%3C%2Fatom%3Acontent%3E%0A%3Cgd%3Aemail+rel%3D%27http%3A%2F%2Fschemas.google.com%2Fg%2F2005%23work%27+primary%3D%27true%27+address%3D%27fifoooo%40gmail.com%27+displayName%3D%27Philippe+Henri+Raymond+Michel+%27%2F%3E%0A+++++++++++++++++++++++++++++++++++++%C3%A9%0A%3Cgd%3AphoneNumber+rel%3D%27http%3A%2F%2Fschemas.google.com%2Fg%2F2005%23work%27+primary%3D%27true%27%3E%0A04442453369%0A%3C%2Fgd%3AphoneNumber%3E%0A%3Cgd%3AphoneNumber+rel%3D%27http%3A%2F%2Fschemas.google.com%2Fg%2F2005%23work%27+primary%3D%27true%27%3E%0A%2B33662473369%0A%3C%2Fgd%3AphoneNumber%3E%0A%3Cgd%3AstructuredPostalAddress+rel%3D%27http%3A%2F%2Fschemas.google.com%2Fg%2F2005%23work%27+primary%3D%27true%27%3E%0A%3Cgd%3Acity%3ESausset+les+pins%3C%2Fgd%3Acity%3E%0A%3Cgd%3Astreet%3E9+Avenue+G%C3%A9n%C3%A9ral+de+Gaulle+%3C%2Fgd%3Astreet%3E%0A%3Cgd%3Apostcode%3E13960%3C%2Fgd%3Apostcode%3E%0A%3Cgd%3AformattedAddress%3E%0A9+Avenue+G%C3%A9n%C3%A9ral+de+Gaulle++13960+Sausset+les+pins%0A%3C%2Fgd%3AformattedAddress%3E%0A%3C%2Fgd%3AstructuredPostalAddress%3E%0A%3C%2Fatom%3Aentry%3E&header=Content-type%3A+application%2Fatom%2Bxml%3B+GData-Version%3A+3.0"
如您所见,gem 如何格式化我的 xml 肯定存在问题....然后是我在调试器中找到的响应
Content-Type application/x-www-form-urlencoded 不是有效的输入类型。
所以我想我的 xml 格式有问题,或者我的内容类型错误