0

我正在尝试使用 Google API 创建一个日历,它只返回我帐户中的日历列表,就像我发送了一个 GET 请求一样。这是我的代码:

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

任何帮助,将不胜感激。

4

2 回答 2

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>
于 2009-08-03T17:51:37.997 回答
0

我首先将您发送的 XML 输出到文本框并在屏幕上显示,以验证其格式是否正确:

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

您可能考虑的另一种方法是将 XML 构建为字符串,而不是稍后转换为字符串的本机 ColdFusion XML 对象:(请注意,我使用的是 CFSaveContent 而不是 CFXML)

<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>
于 2009-08-04T17:36:17.597 回答