Search code examples
facebookfbmlinvitation

Variable interpolation in fb:req-choice url


For my invitation feature of my Facebook Connect app I need to be able to tell which invitation a user responds to. I have decided to rely on the Facebook UID for that. How can I include that ID in the url that Facebook generates for fb:req-choice?

<fb:request-form action="#{@post_url}"
                method="POST"
                invite="true"
                type="my_app"
                content="<fb:name uid='#{current_user.facebook_uid}' useyou='false' /> wants to invite you to to my_app. To join him simple click 'Accept' below.<fb:req-choice url='http://my_app.com/invitation/?fb_uid={uid}' label='Accept' />">
   <fb:multi-friend-selector
              showborder="false"
              actiontext="Invite your Facebook Friends to shop on Yumshare" />
</fb:request-form>

Notice the {uid} in the url attrib for fb:req-choice. This is supposed to be the uid of the user that is being invited and therefore needs to be filled in on Facebooks side. Is that possible?


Solution

  • The solution I used is not totally equivalent to the above, but close enough.

    When loading the page containing the fb:req-choice form, generate a unique token, which of course has to be persisted at that point, and stick that into the acceptance url. Like so:

    <fb:request-form action="#{@post_url}"
                    method="POST"
                    invite="true"
                    type="my_app"
                    content="<fb:name uid='#{current_user.facebook_uid}' useyou='false' /> wants to invite you to to my_app. To join him simple click 'Accept' below.<fb:req-choice url='http://my_app.com/invitation/?token=#{@token}' label='Accept' />">
       <fb:multi-friend-selector
                  showborder="false"
                  actiontext="Invite your Facebook Friends to shop on Yumshare" />
    </fb:request-form>
    

    That way you can track the invitation but only in the batch of friends that the user invited in that action.