Skip to content

Instantly share code, notes, and snippets.

@dator-zz
Created May 16, 2012 13:34
Show Gist options
  • Save dator-zz/2710365 to your computer and use it in GitHub Desktop.
Save dator-zz/2710365 to your computer and use it in GitHub Desktop.
- Prendre le code
- Créer votre app
- Mettre l'url de retour dans les settings de votre app (section: Website with Facebook Login)
- Changer les clefs api dans le code
- Télécharger la lib fb pour php (github.com/facebook/facebook-php-sdk)
- Lancer et Profit!
<?php
require 'facebook/src/facebook.php';
$facebook = new Facebook(array(
'appId' => '227392667376075',
'secret' => '26d1d7c01e02a5f719a2ca8c47898ca0',
));
// Get User ID
$session = $facebook->getUser();
if(!empty($session)) {
try{
$uid = $facebook->getUser();
$user = $facebook->api('/me');
} catch (Exception $e){}
if(!empty($user)){
$friends = $facebook->api('/me/friends');
$Alikes = array();
foreach ($friends['data'] as $k => $friend) {
$likes = $facebook->api('/'.$friend['id'].'/music');
foreach ($likes['data'] as $like) {
if (array_key_exists($like['id'], $Alikes)) {
$Alikes[$like['id']]['score']++;
} else {
$Alikes[$like['id']]['name'] = $like['name'];
$Alikes[$like['id']]['score'] = 1 ;
}
}
if($k == 20) {
break;
}
}
$best = null;
$score = 1;
foreach($Alikes as $l) {
if($l['score'] > $score) {
$best = $l['name'];
}
}
$lastTweets = array();
$search = "http://search.twitter.com/search.json?q=".$best."&lang=fr";
$tw = curl_init();
curl_setopt($tw, CURLOPT_URL, $search);
curl_setopt($tw, CURLOPT_RETURNTRANSFER, TRUE);
$twi = curl_exec($tw);
$twi = json_decode($twi);
} else {
die("There was an error.");
}
} else {
$login_url = $facebook->getLoginUrl(array(
'scope' => 'friends_likes'
));
header("Location: ".$login_url);
}
?>
<html>
<head>
<title>Likes o Likes</title>
</head>
<body>
<h1>Artiste prefere de vos amis : <?php echo $best ?></h1>
<h2>Derniers tweets : </h2>
<ul>
<?php foreach($twi->results as $r): ?>
<li><?php echo $r->from_user?> : <?php echo $r->text; ?></li>
<?php endforeach; ?>
</ul>
</body>
</html>
@VictorNicollet
Copy link

Cool, je vais pouvoir me faire passer pour SupInfoTest maintenant ;-)

@dator-zz
Copy link
Author

Le secret a été changé avant la mise en ligne du gist ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment