Copy link to clipboard
Copied
Hi All,
I'm fooling around with the Google API's and am trying to output the result of a CFHTTP call for each user found in a db table. My code seems to process ok...no errors but the value of the two variables I'd expect to exist are the same. I'm sure I'm doing something silly in the loop that messing it up. Any thoughts?
<cfloop query = "getTokens">
<cfhttp url="https://www.googleapis.com/latitude/v1/currentLocation" result="#tokName#">
<cfhttpparam type="header" name="Authorization" value="OAuth #application.token.access_token#" >
<cfhttpparam type="url" name="granularity" value="best" >
</cfhttp>
<cfset "apidata#tokName#" = #DeserializeJSON( evaluate("#tokName#.FileContent") )#>
</cfloop>
Thx!
PS - Also, how to you CFDUMP a dynamically named var such as the one created in the code above?
Copy link to clipboard
Copied
use array notation to dump dynamically named variables. #variables["static_part" & variable_part]#
Copy link to clipboard
Copied
You could simplify it as follows:
<cfset apidata = arrayNew(1)>
<cfloop query = "getTokens">
<cfhttp url="https://www.googleapis.com/latitude/v1/currentLocation" result="arbitraryName">
<cfhttpparam type="header" name="Authorization" value="#getTokens.query_column_name_representing_auth#" >
<cfhttpparam type="url" name="granularity" value="best" >
</cfhttp>
<cfset apidata[getTokens.currentrow] = deserializeJSON(arbitraryName.FileContent)>
</cfloop>