函数参数中的 Coldfusion 结构

发布于 2025-01-03 01:57:10 字数 1067 浏览 8 评论 0原文

我正在尝试进行服务器端 facebook 连接,但是 sdk (在这里获取< /a>) 提供了以下错误:

Invalid CFML construct found on line 523 at column 78.
ColdFusion was looking at the following text:

{

并且它没有解释为什么会抛出此错误。我不擅长 cfscript,所以我不知道 sdk 是否使用正确的语法,但它在函数参数中的结构大括号处抛出了这个函数的错误:

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]);
    }

Are you not allowed to use a for loop in cfscript?

I'm trying to do server side facebook connect, but the sdk (get it here) provided gives the following error:

Invalid CFML construct found on line 523 at column 78.
ColdFusion was looking at the following text:

{

And it doesn't explain why it's throwing this error. I'm not good at cfscript, so I don't know whether the sdk uses the correct syntax, but it throws the error on this function, at the braces of the struct in the function arguments:

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

I had thought that using an sdk would be a no brainer, but apparently I'm missing something.
What am I doing wrong?

Part 2:
The code now comes to a halt at:

for (var propertyName in arguments.properties) {
        httpService.addParam(type="formField", name=propertyName, value=arguments.properties[propertyName]);
    }

Are you not allowed to use a for loop in cfscript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔嚣张 2025-01-10 01:57:10

尝试 structNew() 或“#structNew()#”而不是 {}

Try structNew() or "#structNew()#" instead of {}

刘备忘录 2025-01-10 01:57:10

这应该适用于连接到 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>

This should work for connecting to Facebook and getting an access token:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文