Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 14th, 2012  |  syntax: None  |  size: 1.69 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. get page contents and json_decode loading issue
  2. //facebook
  3. $fdata = file_get_contents('http://graph.facebook.com/http://theoatmeal.com/comics/127_hours');
  4. $fdata = json_decode($fdata);
  5. if($fdata->shares) {
  6.     $share_count['facebook'] = $fdata->shares;
  7. }
  8.        
  9. require "facebook.php";
  10. $facebook = new Facebook(array(
  11.     'appId'  => YOUR_APP_ID,
  12.     'secret' => YOUR_APP_SECRET,
  13. ));
  14.  
  15. $user = $facebook->getUser();
  16.  
  17. if ($user) {
  18.     try {
  19.         $user_profile = $facebook->api('/me');
  20.     } catch (FacebookApiException $e) {
  21.         $user = null;
  22.     }
  23. }
  24.        
  25. $result = $facebook->api(...);
  26.        
  27. <?php if ($user): ?>
  28.     <a href="<?php echo $facebook->getLogoutUrl() ?>">Logout of Facebook</a>
  29. <?php else: ?>
  30.     <a href="<?php echo $facebook->getLogoutUrl() ?>">Login with Facebook</a>
  31. <?php endif ?>
  32.        
  33. $fql = 'SELECT total_count FROM link_stat WHERE url="http://google.com"';
  34. $json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
  35. $data = json_decode($json);
  36. echo $data[0]->total_count;
  37.        
  38. SELECT url, total_count FROM link_stat WHERE url="..." OR url="..."
  39.        
  40. $urls = array(
  41.     "http://google.com",
  42.     "http://twitter.com",
  43.     "http://stackoverflow.com",
  44.     "http://linkedin.com"
  45. );
  46.  
  47. function wrap($url) {
  48.     return 'url="' . $url . '"';
  49. }
  50.  
  51. $fql = 'SELECT url, total_count FROM link_stat WHERE ';
  52. $fql .= implode(" OR ", array_map("wrap", $urls));
  53.  
  54. $json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
  55. $data = json_decode($json);
  56.        
  57. array(4) {
  58.   [0]=> object(stdClass)#2 (2) {
  59.     ["url"]=> string(17) "http://google.com"
  60.     ["total_count"]=> int(1318598)
  61.   }
  62.   [1] => ...
  63.   [2] => ...
  64.   [3] => ...
  65. }