views:

327

answers:

2

I am trying to create a caledar using the Google API, and it just returns the list of calendars in my account, just like I sent a GET request. Here is my code:

        <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"&gt;
                <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>

Any help would be appreciated.

A: 

CFXML creates a ColdFusion XML object. That's an internal CFML construct and is not going to mean anything to the receiving API. I expect that you need to convert it into text.

Try wrapping locals.xml with a ToString(). Like so:

<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>
Al Everett
I made that change, and I still get a 200 and no new calendar is created.
KingErroneous
Ah. Well then. I'm afraid I don't know enough about the Google APIs to offer anything more constructive.
Al Everett
A: 

I would start by outputting the XML you're sending into a text-box and displaying it on-screen, to verify that it's in the correct format:

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

Another approach you might consider would be to build your XML as a string, not a native ColdFusion XML object that you later convert to a string: (notice that I'm using CFSaveContent instead of 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"&gt;
        <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>
Adam Tuttle
I changed it to a cfsavecontent and it still doesn't work. In fact, I changed it to the example on the Google API page and that doesn't work either.
KingErroneous
Can you be more specific? "It doesn't work" doesn't help much.
Adam Tuttle