如何发送链接到外部网站的 Facebook 请求?

发布于 2024-12-12 14:54:04 字数 1263 浏览 4 评论 0原文

在我当前基于 .NET 和 FBML 的 facebook 应用程序中,我有一些如下所示的代码:

<fb:request-form
        action="http://mysite.com/InvitesSent.aspx"
        method="POST"
        invite="true"
        type="SomeType"
        content="Here is an invite to <fb:req-choice url='http://mysite.com?<%=Params %>' label='My site' />">
    <fb:multi-friend-selector
            max="20"
            actiontext="Invite your friends!"
            showborder="false"
            rows="4"
            bypass="cancel"
            email_invite="false"
            exclude_ids="" /> 
</fb:request-form>

这会在我的网站上弹出多朋友选择器,用户从中选择一些朋友并按“发送邀请”,此时用户被重定向到 http://mysite.com/InvitesSent.aspx

在另一端,邀请的收件人会看到带有“接受”按钮的通知。当按下按钮时,facebook 立即重定向到我的网站,

http://www.facebook.com/l.php?u=http%3A%2F%2Fmysite.com%3F ...

这是 facebook 的外部链接重定向。此重定向包括我在 fb:req-choice url 属性中提供的参数。

我的问题是:由于 FBML 即将停止,我如何在 Javascript SDK 中实现此行为?

我可以使用 FB.ui 和 apprequest 发送通知,但我似乎无法像在 FBML 中那样将参数附加到 URL。我需要这个,因为我希望奖励邀请者,为此我需要能够跟踪个人请求。

在新的 SDK 中这一切都可能实现吗?该文档令人困惑,有时会区分请求和邀请,有时则不会。老实说,我不太确定是否存在差异,我只是紧紧抓住 FBML 中的线索,例如“invite =“true””,这可能会帮助我找到解决方案。

In my current .NET and FBML-based facebook app, I have some code that looks like this:

<fb:request-form
        action="http://mysite.com/InvitesSent.aspx"
        method="POST"
        invite="true"
        type="SomeType"
        content="Here is an invite to <fb:req-choice url='http://mysite.com?<%=Params %>' label='My site' />">
    <fb:multi-friend-selector
            max="20"
            actiontext="Invite your friends!"
            showborder="false"
            rows="4"
            bypass="cancel"
            email_invite="false"
            exclude_ids="" /> 
</fb:request-form>

This pops up the multi-friend selector on my site from which the user selects some friends and presses 'send invitations' at which point the user is redirected to http://mysite.com/InvitesSent.aspx.

At the other end, the recipients of the invite see a notification with an 'Accept' button. When the button is pressed, facebook redirects immediately to my site with

http://www.facebook.com/l.php?u=http%3A%2F%2Fmysite.com%3F ...

which is facebook's external link redirect thing. This redirect includes the parameters I supplied in the fb:req-choice url attribute.

My question is this: Since FBML is due to be discontinued, how do I achieve this behaviour in the Javascript SDK?

I can send notifications with FB.ui and apprequest, but I don't appear to be able to tack on parameters to the URL as I can in FBML. I need this since I wish to reward the inviter and for that I need to be able to track individual requests.

Is any of this even possible in the new SDK? The documentation is confusing and sometimes makes distinctions between requests and invites, and sometimes not. To be honest, I'm not really sure if there is a difference, I'm just clinging on to clues in the FBML such as 'invite="true"' that might help me to divine a solution.

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

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

发布评论

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

评论(1

终止放荡 2024-12-19 14:54:04

这是不可能的了,从 开发人员文档

用户响应

如果用户在请求上单击“接受”,他们将被发送到发送请求的应用程序的画布 URL。此 URL 将包含一个附加参数 request_ids,它是用户尝试执行操作的请求 ID 的逗号分隔列表:

http://apps.facebook.com/[app_name]/?request_ids=[request_ids]
作为用户登陆您的应用程序时的最佳实践,您应该阅读未完成的应用程序请求。如果用户单击仪表板中的通知或请求,您将通过 URL 传递请求 ID。然后,当用户处理请求时,您应该通过 Graph API 删除它们。

当用户点击 Facebook API 中的“接受”时,Requests 2.0 请求不会被删除。您必须使用 Graph API 读取并清除它们。

所以你可以尝试的是:

  1. 当用户向她的朋友发送邀请/请求时,读取 javascript 回调中的 request_ids,并使用 ajax 将它们存储到您的数据库中(这样您就可以调用 < code>InvitesSent.aspx)。

  2. 当新用户到来时,读取 request_id 并奖励发送请求的用户。

如果您能告诉我当用户从外部网站发送请求并且另一个用户接受新的 JS SDK 时会发生什么,我可以更具体地说明解决方案。基本上,如果您密切关注浏览器网址,您就会了解 Facebook 如何重定向接受的新用户。在文档中,仅针对画布应用程序提到了接受,因此我不确定外部网站会发生什么。如果你测试一下我们就能弄清楚。
编辑:
正如 Igy 所建议的,我想接受请求总是会重定向到画布。

It's not possible anymore, which is evident from the following paragraph in the developer documentation

User Response

If a user clicks 'Accept' on a request, they will be sent to the canvas URL of the application that sent the request. This URL will contain an additional parameter, request_ids, which is a comma delimited list of Request IDs that a user is trying to act upon:

http://apps.facebook.com/[app_name]/?request_ids=[request_ids]
As a best practice when the the user lands in your app you should read outstanding app requests. If the user clicked on a notification or request from the Dashboard you will be passed the request ID via the URL. Then as the user handles the request(s) you should delete them via the Graph API.

Requests 2.0 requests will not get deleted when a user clicks on accept in Facebook’s API. You must read and clear them using the Graph API.

So what you can try is this :

  1. when a user sends invites/requests to her friends, read the request_ids in the javascript callback, and store them into your db with ajax(so you can call InvitesSent.aspx).

  2. When a new user comes read the request_id and reward the user who sent the request.

If you can tell me what happens when a user sends a request from an external web site and another user accepts, with the new JS SDK, i can be more specific with the solution. Basically if you keep an eye on the browser url, you'll come to know how facebook is redirecting the new user who accepted. In the documentation accepting is mentioned only for canvas apps, so i'm not sure what happens for an external site. If you test it we can figure it out.
EDIT:
As Igy suggested, i guess accepting a request will always redirect to the canvas.

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