Question

I'm trying to do some sanitation on the results of a call to Facebook but Coldfusion is telling me that the variable is null:

FILECONTENT null <br>The error occurred on line 66.

Here's the line that causes the error:

<cfif isDefined("storeFeedJSON.fileContent")>
    <cfset storeFeedJSON.fileContent = process.CleanBadUnicode("#storeFeedJSON.fileContent#")>
</cfif>

The struct is clearly not null however as I have it wrapped in an "isDefined" and when I dump storeFeedJSON I can see fileContent looks like

{"data":[]}

Empty JSON but still not null...

EDIT: Here's the call I forgot to put in there:

<cfset fbURL = "https://graph.facebook.com/#qStoreFBPages.pageID#/#fbEdge#?fields=#fbFields#&since=#fbSinceTime#&#qToken.objectValue#">
    <cfhttp result="storeFeedJSON" url="#fbURL#" method="get"></cfhttp>

which would probably end up looking something like this:

<cfhttp result="storeFeedJSON" url="https://graph.facebook.com/1749383765/posts?fields=created_time&since=1389296713&access_token=CAAH6oehQqUUU2IALvt0ZB3mdE6E2LCaldFc1TjIqxALUZBMqZC01O2hQXkOX8ROI9QBHn7WjWrHHneazAP4gWbj0MBsRUlel9TAG52kjBm0bBOUHVEFmEusEUHfhznlqzH1GMgCpCU4z4SmgXU8oFZBPDyAv1ByJu167jgkVd6UROWtDZBNBCP&expires=5184000" method="get"></cfhttp>

Note that will not result in a valid response from Facebook as I've changed my token and some other params.

Was it helpful?

Solution

I don't think you can re-assign the properties of the storeFeedJSON struct. storeFeedJSON is the result of your cfhttp, right? as in

<cfhttp url="xyz" result="storeFeedJSON">

... which I think is a protected or immutable data structure. You can obviously pass it as an argument for your function, but put the output in some other variable, or perhaps straight to the json deserialize.

<cfset local.cleanFileContent = process.CleanBadUnicode(storeFeedJSON.fileContent)>
<cfdump var="#deserializeJSON(local.cleanFileContent)#">

... and while I'm at it, you might want to use getasbinary="never" because Facebook may someday give you binary data, or change its headers or something, and then your code will break. If you have to receive binary, you'll need cfhttp.fileContent.toString() or something like that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top