如何发送链接到外部网站的Facebook请求? [英] How do I send a facebook request that links to an external site?

查看:335
本文介绍了如何发送链接到外部网站的Facebook请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  

在我目前的.NET和FBML的Facebook应用程序中,我有一些代码如下: fb:request-form
action =http://mysite.com/InvitesSent.aspx
method =POST
invite =true
type =SomeType
content =这是邀请到< fb:req-choice url ='http://mysite.com?<%= Params%>'label ='我的网站'/> >
< fb:multi-friend-selector
max =20
actiontext =邀请你的朋友!
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发送通知,但是我似乎无法将URL参数粘贴到可以在FBML中我需要这个,因为我希望奖励邀请者,因此我需要能够跟踪个人的请求。



这个新的SDK中有甚么可能吗?这些文件令人困惑,有时会让请求和邀请之间有区别,有时也不会。说实话,我不确定是否有区别,我只是坚持FBML中的线索,比如'invite =true,这可能有助于我解决问题。

解决方案

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


用户响应



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



http://apps.facebook .com / [app_name] /?request_ids = [request_ids]
作为用户登陆您的应用程序的最佳做法,您应该看到优秀的应用程序请求。如果用户从信息中心点击通知或请求,您将通过该URL传递请求ID。然后,当用户处理请求时,您应该通过Graph API删除它们。



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


所以你可以尝试是这样的:


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


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


如果你能告诉我,当一个用户从一个外部网站和另一个用户接受新的JS SDK,我可以更具体的解决方案。基本上,如果您关注浏览器网址,您将会了解Facebook如何重定向接受的新用户。在文档接受中仅提及画布应用程序,所以我不知道外部网站会发生什么。如果你测试它,我们可以弄清楚。

编辑:

按照Igy的建议,我想接受请求将总是重定向到画布。


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.

解决方案

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.

这篇关于如何发送链接到外部网站的Facebook请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆