// nell'applicazione ho configurato il Canvas URL su:
// http://apps.facebook.com/angel_f/
//
// e il Canvas Callback URL su:
// http://beyourbrowser.com/autoangel/monochrome/
//
// questo quindi stabilisce il collegamento tra il mio software e quello che si vede su facebook.
//
// Per esempio quando devo chiamare una funzione che fa l'invite di utenti su una applicazione, io chiamo:
// http://apps.facebook.com/angel_f/invite.php?fb_force_mode=fbml
//
// che corrisponde al mio:
// http://beyourbrowser.com/autoangel/monochrome/invite.php?fb_force_mode=fbml
//
// dentro invite.php ci metto almeno questi pezzi:
$api_key = 'METTICI_API_KKEY';
$secret = 'METTICI_APP_SECRET';
$app_name = "Angel_F, a digital child";
// questo e' quello che definisci nell'applicazione di FB
$app_url = "angel_f";
// questo e' l'include delle API di facebook
require_once 'php/facebook.php';
$facebook = new Facebook($api_key, $secret);
$facebook->require_frame();
$user = $facebook->require_login();
// e poi uso le variabili che mi manda FB per fare le cose: ad esempio su "ids" mi ci mette gli id degli invitati
if(isset($_POST["ids"])) {
echo "
Thank you for inviting ".sizeof($_POST["ids"])." of your friends on ".$app_name.".
";
echo("");
}
// oppure se io voglio posso usare delle variabili nelle chiamate per gestirmi il flusso.
// se per esempio definisco:
$invite_href = "invite.php?fb_force_mode=fbml&comingfrom=invite";
// posso fare:
else if(isset($_GET["comingfrom"])) {
echo "
";
echo("");
}
// se devo cercare delle info posso fare delle query:
// Retrieve array of friends who've already authorized the app.
$fql = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.$user.') AND is_app_user = 1';
$_friends = $facebook->api_client->fql_query($fql);
// Extract the user ID's returned in the FQL request into a new array.
$friends = array();
if (is_array($_friends) && count($_friends)) {
foreach ($_friends as $friend) {
$friends[] = $friend['uid'];
}
}
// Convert the array of friends into a comma-delimeted string.
$friends = implode(',', $friends);
// Prepare the invitation text that all invited users will receive.
$content = " has met Angel_F here at ".$app_name." and would like you to get to know little ANgel_F as well.!\n". "get_add_url()."\" label=\"Put ".$app_name." on your profile\"/>";
?>
//
//
// per pubblicare delle info sul profilo FB posso fare cosi'
//
//
// FB mi passa una variabile method
$method = "";
if(isset($_GET["method"])){
$method = $_GET["method"];
} else if(isset($_POST["method"])){
$method = $_POST["method"];
}
// in questo caso devo mostrare l'interfaccia per inserire il contenuto
if($method=="publisher_getInterface"){
?>
{"content":
{
"fbml":"Would you like to share a thought coming from Angel_F's digital mind?
What would you like to talk about? ",
"publishEnabled":true
},
"method":"publisher_getInterface"
}
// in questo altro caso raccolgo le variabili che ho fatto inserire nel passo precedente e formatto il contenuto da pubblicare
} else if($method=="publisher_getFeedStory"){
$contents = "";
$greet = "Hello";
if(isset($_POST["name"])){
$greet = $greet . " " .$_POST["name"];
}
$query = "";
if(isset($_POST["app_params"])){
$appa = $_POST["app_params"] ;
if(isset($appa["query"])){
$query = $appa["query"];
}
}
$greet = $greet . ", ";
$contents = "blablabla";
// qui pubblico contemporaneamente su twitter e su FB
// vedi piu' in basso per la definizione della funzione postToTwitter
$twitter_status=postToTwitter($twitter_username, $twitter_psw, $contents);
// qui formatto i parametri che ho configurato in un template quando ho creato l'applicazione
// ad esempio il mio template e':
$tokens = array(
'query'=>$query,
'generated'=>$contents,
'images'=>array(array('src'=>'http://www.beyourbrowser.com/autoangel/monochrome/icon.png', 'href'=>'http://www.angel-f.it'))
);
$toks = json_encode($tokens);
// e qui faccio l'echo dei parametri che definiscono quello che voglio pubblicare
?>
{"content":
{
"feed":
{
"template_id":140453082549,
"template_data":
= $toks ?>
}
},
"method":"publisher_getFeedStory"
}
See your profile';
} else {
$twitter_status="Error posting to Twitter. Retry[" . $resultArray['http_code'] . "]";
}
return $twitter_status;
}
$twitter_username ='angeleffe';
$twitter_psw ='anghel4Eff3,£';
?>
$title".
"$categories".
$body;
$params = array('','',$username,$password,$XML,1);
$request = xmlrpc_encode_request('blogger.newPost',$params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $rpcurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_exec($ch);
curl_close($ch);
}
// questo qui e' il xmlrpc.inc che trovate qui: http://phpxmlrpc.sourceforge.net/
require_once ('xmlrpc/lib/xmlrpc.inc');
?>