2012-06-16 53 views
2

我一直在抓這些問題,因爲我不知道在哪裏挖,所以我希望有人能幫助我。 正如標題所說,我正在使用omniauth google oauth2進行身份驗證的項目。這部分從一開始就工作正常。 下一部分是在谷歌聯繫人API中創建聯繫人,它不起作用。使用oauth2在rails中創建谷歌聯繫人

由於要生成的XML /原子有點沉重,我決定使用xml視圖並使用render_to_string在我的控制器中檢索它。由於我對軌道的瞭解不多,我只是覺得它更清潔。這工作正常。

因此,這裏是我的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'}) 

當調試調用我可以看到像

"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" 

的URL生成看起來就像你看到的肯定有一個關於如何創業板的格式問題我的xml .... 然後發現我在調試器中找到的響應

Content-Type應用程序/ x-www-form-urlencoded不是有效的輸入類型。

,所以我想我有我的XML的格式問題,也許我的內容類型錯誤

回答

0

確定這裏是正確的方式來調用它:

strxml = render_to_string(:partial => 'createInGoogle', :layout => false) 
response = access_token.post('/m8/feeds/contacts/default/full', {:body => strxml, :header => {'Content-type' => 'application/atom+xml;GData-Version: 3.0'}})