我正在尝试进行服务器端facebook连接,但提供的sdk(get it here)会出现以下错误:
Invalid CFML construct found on line 523 at column 78.
ColdFusion was looking at the following text:
{
并没有解释为什么它会抛出这个错误。我不擅长cfscript,所以我不知道sdk是否使用了正确的语法,但它在函数参数中的struct的大括号上抛出了这个函数的错误:
private String function getUrl(String path = "", Struct parameters = {})
{
var key = "";
var resultUrl = "https://www.facebook.com/" & arguments.path;
if (structCount(arguments.parameters)) {
resultUrl = resultUrl & "?" & serializeQueryString(arguments.parameters);
}
return resultUrl;
}
我原本以为使用sdk会毫无疑问,但显然我错过了一些东西。 我做错了什么?
第2部分: 现在代码暂停:
for (var propertyName in arguments.properties) {
httpService.addParam(type="formField", name=propertyName, value=arguments.properties[propertyName]);
}
你不允许在cfscript中使用for循环吗?
答案 0 :(得分:3)
尝试使用structNew()或“#structNew()#”而不是{}
答案 1 :(得分:1)
这应该适用于连接到Facebook并获取访问令牌:
<cfset appID = ""/>
<cfset secret_key = ""/>
<cfset app_url = ""/>
<cfparam name="URL.Code" default="0">
<cfparam name="URL.state" default="0">
<cfparam name="SESSION.Redirect" default="0">
<cfset code_ = URL.Code>
<cfif code_ EQ "" OR code_ EQ 0>
<cfset SESSION.State = Hash(CreateUUID(),"MD5")>
<cfset dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" & appID & "&redirect_uri=" & app_url & "&scope=email,user_photos,publish_stream" & "&state=" & SESSION.State>
<cflocation url="#dialog_url#" addtoken="no">
</cfif>
<cfif SESSION.State EQ URL.State>
<cfset token_url = "https://graph.facebook.com/oauth/access_token?client_id=" & appID & "&redirect_uri=" & app_url & "&client_secret=" & secret_key & "&code=" & code_>
<cfhttp url="#token_url#" result="AccessToken" method="GET">
<cfelse>
<p>The state does not match. You may be a victim of CSRF.</p>
</cfif>