How do I send a facebook request that links to an external site?
Asked Answered
P

1

2

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.

Plotkin answered 27/10, 2011 at 9:54 Comment(0)
L
3

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.

Liddy answered 27/10, 2011 at 10:38 Comment(4)
Just process the request on your canvas URL and then send the user back to your main app off Facebook; i strongly recommend not doing it silently / automatically as it makes for a poor user experience. The expectation when accepting a request is that it'll take you somewhere on facebook.com so automatically forwarding elsewhere is unexpected in most cases. If you don't want to have a canvas app at all, requests probably aren't a good channel to useFailure
@Failure so incase izb doesn't have a canvas app, and has only a website, is it possible to track feed posts, as in when the user visits the link in the feed post, is the post_id appended to the url?Liddy
For the record, I don't have a canvas app.Plotkin
I think you should then try and use feed posts and reward people, (whose posts were clicked), resulting in the traffic to your site. Reading the documentation at first glance i couldn't figure out how you can track a post, that was clicked. So you'll have to do some experimentation. Incase u figure it out do post it here, i would be interested in a solution too. Incase i figure out something, will edit my answer :)Liddy

© 2022 - 2024 — McMap. All rights reserved.