如何发送链接到外部网站的 Facebook 请求?
在我当前基于 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是不可能的了,从 开发人员文档
所以你可以尝试的是:
当用户向她的朋友发送邀请/请求时,读取 javascript 回调中的 request_ids,并使用 ajax 将它们存储到您的数据库中(这样您就可以调用 < code>InvitesSent.aspx)。
当新用户到来时,读取 request_id 并奖励发送请求的用户。
如果您能告诉我当用户从外部网站发送请求并且另一个用户接受新的 JS SDK 时会发生什么,我可以更具体地说明解决方案。基本上,如果您密切关注浏览器网址,您就会了解 Facebook 如何重定向接受的新用户。在文档中,仅针对画布应用程序提到了接受,因此我不确定外部网站会发生什么。如果你测试一下我们就能弄清楚。
编辑:
正如 Igy 所建议的,我想接受请求总是会重定向到画布。
It's not possible anymore, which is evident from the following paragraph in the developer documentation
So what you can try is this :
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
).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.