Hi guys,
Okay, first things first. Your app should not be separate from your website. For me, usually I use something like:
root
¦ files and folders
¦
+---facebook
¦
¦
+---app_name
¦ index.php
¦
+---canvas
¦ ¦ index.php
¦ ¦
¦ +---tab
¦ ¦ index.php
¦ ¦
¦ +---css
¦ main.css
¦ reset.css
¦
+---src
facebook.php
fb_ca_chain_bundle.crt
(
reference)
I put the Facebook app inside a folder called "facebook" because sometimes you may have more than one application on the same domain.
Also as you can see I have a folder called "tab" there I put all my "Facebook pages" related apps code, in the
documentation:
Your Tab URL must be relative to your Canvas Page and therefore your Canvas URL. Using our previous Canvas Page and Canvas URL settings would results in Facebook loading content from "
http://www.example.com/canvas/tab."
Okay, so now you have all your website under the "root" and all your Facebook related stuff under "facebook". As you can see it's all there under the same host (just like having a wordpress blog folder and a forum next to it).
A last note here, your "src" folder can be placed in the "facebook" folder if you are planning to have multiple apps
----------------------------
Now in your code above, users are sending invitations to their friends. These invitations have ids (obviously) which will allow you to access its details at a later stage.
Now the reason why storing these ids is important is described in my first
tutorial:
The reason of doing this is to save the request ids along with the “sender/inviter” id ($uid). For me, this is very important since Facebook will only give you the ability to access this request by knowing the “receiver/invitee” or the request id!
So the only way to track these invitations is by knowing the "request id" (which why we are storing it)
OR when the user's friend actually add the app where you can use this graph call "/me/apprequests" to get the requests ids!
Which (for me) is very stupid because for some reason if you lose the request id (or you didn't save it). And the user's friend never respond to the request you'll never know! and you'll never know if the user is actually sending anything to his friends!!
----------------------------
Kassem wroteYup I did. And I've checked the documentation and apparently I'm going totally wrong about it. My main purpose is to simply invite them to the app which will simply redirect them to my registration page (once they accept the invitation) AND most importantly be able to track the person who invited them using an invitation code (which will basically be a Guid). In the docs, it says that the return data is actually the request_ids, which is not really what I'm looking for (although it could be useful to me).
If the only thing you need to know when sending the users who are clicking on the invitation links is the "sender id" then no need for the "data" field at all because the "request" itself will have this piece of information. Refer to the
documentation to check the request structure.
So the steps are:
1- the friend clicks on the link, gets redirected to your application INSIDE Facebook along with the request id/s he clicked
2- you read these "ids", extract the sender id, save it to the session or add it to your url (query string) and redirect the friend to your website!
----------------------------
Now some important notes to Kassem & ZeRaW:
ZeRaW wroteHey Kassem,
you can send data with the invitation (invitation code).
When the user clicks on accept it will redirect to the canvas URL of your app.
This is not necessary true!
From my second
tutorial:
But be aware if you are setting the Bookmark URL in your application settings, Facebook will send the user to that url instead.
Also:
In your code, you are doing the following:
if($_REQUEST['request_ids']==$request_info['data'][$request_num]['id']) //If the 'request_ids' parameter is equal to the request data's sending ID.
This is
not always true, based on the documentation:
If a user clicks 'Accept' on a request, they will be sent to the canvas URL of the application that sent the request with a new parameter ‘request_ids’, which is a comma delimited list of identifiers for the requests that a user trying to act upon; in this version, it will always be a single id since they are coming from the games dashboard, but it may be several in the future.
Also in your code, you are assuming that the landing use is already an app user since you are using "me"! which is again not always the case.
Also you are not deleting the request after processing it and you should remember:
As a best practice, you should upon landing, read the outstanding app requests for that user as well as the ids that the user is trying to act upon. Then, delete requests when the user ignores or handles them and potentially highlight the ones the user came in to act upon.
Requests 2.0 will not get deleted when a user clicks on accept in Facebook’s API. You must read and clear them using the Graph API.
Sorry for the long post :-)
ifaour