Created
May 16, 2012 13:34
-
-
Save dator-zz/2710365 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
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
Cool, je vais pouvoir me faire passer pour SupInfoTest maintenant ;-)