问题
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.
回答1:
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 :
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.
来源:https://stackoverflow.com/questions/7914296/how-do-i-send-a-facebook-request-that-links-to-an-external-site