2009-08-03 155 views
0

我正尝试使用Google API创建caledar,它只是返回我帐户中的日历列表,就像我发送GET请求一样。这里是我的代码:通过ColdFusion在Google API中创建日历时遇到困难

 <cfxml variable="locals.xml"> 
      <cfoutput> 
      <entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" xmlns:gCal="http://schemas.google.com/gCal/2005"> 
       <title type="text">#arguments.argTitle#</title> 
       <summary type="text">#arguments.argSummary#</summary> 
       <cfif len(arguments.argTimezone)><gCal:timezone value="#arguments.argTimezone#"></gCal:timezone></cfif> 
       <gCal:hidden value="false"></gCal:hidden> 
       <gCal:accesslevel value="owner" /> 
       <gCal:color value="#arguments.argColor#"></gCal:color> 
       <gd:where rel='' label='' valueString='Oakland'></gd:where> 
      </entry> 
      </cfoutput> 
     </cfxml> 

     <cfhttp url="#variables.baseURL#/default/owncalendars/full" method="post" redirect="false" multiparttype="related" charset="utf-8"> 
      <cfhttpparam type="header" name="Authorization" value="GoogleLogin auth=#getAuth(variables.serviceName)#"> 
      <cfhttpparam type="header" name="Content-Type" value="application/atom+xml"> 
      <cfhttpparam type="header" name="GData-Version" value="2"> 
      <cfhttpparam type="body" value="#trim(locals.xml)#"> 
     </cfhttp> 

任何帮助,将不胜感激。

+0

雷卡姆登有一些一些goog le api - 你检查了他的博客吗? – Antony 2009-08-03 22:50:26

+0

是的......我正在使用他的api,我正在扩展使用日历(他的代码不包含文档和分析)。我写了一个函数,它可以成功地获取帐户中的日历。但是,我正在遵循我在所看到的所有网站上看到的示例以及google api页面,并且似乎无法让它创建日历,因为它忽略了我发送的标头信息。 – KingErroneous 2009-08-04 15:59:50

+0

我想通了......我没有通过gSessionId,重定向失去了标题信息......感谢您的帮助。 – KingErroneous 2009-08-04 23:18:21

回答

0

CFXML创建一个ColdFusion XML对象。这是一个内部的CFML构造,对接收API不会有任何意义。我希望你需要将它转换成文本。

尝试用ToString()包装locals.xml。像这样:

<cfhttp url="#variables.baseURL#/default/owncalendars/full" method="post" 
    redirect="false" multiparttype="related" charset="utf-8"> 
    <cfhttpparam type="header" name="Authorization" value="GoogleLogin 
     auth=#getAuth(variables.serviceName)#"> 
    <cfhttpparam type="header" name="Content-Type" 
     value="application/atom+xml"> 
    <cfhttpparam type="header" name="GData-Version" value="2"> 
    <cfhttpparam type="body" value="#trim(toString(locals.xml))#"> 
</cfhttp> 
0

我会通过输出要发送到文本框中的XML并在屏幕上显示出来,以验证它是正确的格式开始:

<textarea rows="30" cols="120"> 
    <cfoutput>#trim(toString(locals.xml))#</cfoutput> 
</textarea> 

另一个你可以考虑的方法是建立你的XML作为一个字符串,而不是原生的ColdFusion XML对象,你以后转换为字符串:(请注意,我用的,而不是CFXML CFSaveContent)

<cfsavecontent variable="locals.xml"> 
    <cfoutput> 
    <entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" xmlns:gCal="http://schemas.google.com/gCal/2005"> 
     <title type="text">#arguments.argTitle#</title> 
     <summary type="text">#arguments.argSummary#</summary> 
     <cfif len(arguments.argTimezone)><gCal:timezone value="#arguments.argTimezone#"></gCal:timezone></cfif> 
     <gCal:hidden value="false"></gCal:hidden> 
     <gCal:accesslevel value="owner" /> 
     <gCal:color value="#arguments.argColor#"></gCal:color> 
     <gd:where rel='' label='' valueString='Oakland'></gd:where> 
    </entry> 
    </cfoutput> 
</cfsavecontent>