/fb/facebook_api.php

https://github.com/josenelson/FbHackathon · PHP · 148 lines · 108 code · 29 blank · 11 comment · 3 complexity · 60879947ed523874881a83b70a440089 MD5 · raw file

  1. <?php
  2. require 'facebook.php';
  3. $appId = '212608815478069';
  4. $secret = 'ab11a960a632e4b3c26d5682f9861109';
  5. $url = 'http://localhost/FbHackaton';
  6. $facebook = new Facebook(array(
  7. //'appId' => '191149314281714',
  8. //'secret' => '73b67bf1c825fa47efae70a46c18906b',
  9. 'appId' => '212608815478069',
  10. 'secret' => 'ab11a960a632e4b3c26d5682f9861109',
  11. ));
  12. // Get User ID
  13. $user = $facebook->getUser();
  14. $access_token = $facebook->getAccessToken();
  15. $_SESSION["user"] = $user;
  16. $_SESSION["facebook"] = $facebook;
  17. $_SESSION["access_token"] = $facebook->getAccessToken();
  18. $_SESSION["appId"] = $appId;
  19. $_SESSION["url"] = $url;
  20. //'AAAAAAITEghMBAIVb8ShZCiu1RlOypQgh8ij6QdRnycXxBsbdtrhU0TDoJNA0hwJdHzYKqequpszXYdYg2P9L2zAocSG4aJoBAWg0UBKRDgKymnbRZA';
  21. // We may or may not have this data based on whether the user is logged in.
  22. //
  23. // If we have a $user id here, it means we know the user is logged into
  24. // Facebook, but we don't know if the access token is valid. An access
  25. // token is invalid if the user logged out of Facebook.
  26. if ($user) {
  27. try {
  28. // Proceed knowing you have a logged in user who's authenticated.
  29. $user_profile = $facebook->api('/me');
  30. } catch (FacebookApiException $e) {
  31. error_log($e);
  32. $user = null;
  33. }
  34. }
  35. // Login or logout url will be needed depending on current user state.
  36. if ($user) {
  37. $_SESSION["logoutUrl"] = $facebook->getLogoutUrl();
  38. $_SESSION["isfacebooklogin"] = true;
  39. } else {
  40. $_SESSION["loginUrl"] = $facebook->getLoginUrl();
  41. $_SESSION["isfacebooklogin"] = false;
  42. }
  43. function isLoggedin() {
  44. return $_SESSION["isfacebooklogin"];
  45. }
  46. function getLoggedUserId() {
  47. return $_SESSION["user"];
  48. }
  49. function getCurrentUserInfo() {
  50. return getUserInfo($_SESSION["user"]);
  51. }
  52. function getUserInfo($userid) {
  53. $jsonurl = "https://graph.facebook.com/" . $userid;
  54. $json = file_get_contents($jsonurl,0,null,null);
  55. $json_output = json_decode($json);
  56. return $json_output;
  57. }
  58. function getEventInfo($eventid) {
  59. $jsonurl = "https://graph.facebook.com/" . $eventid;
  60. $json = file_get_contents($jsonurl,0,null,null);
  61. $json_output = json_decode($json);
  62. return $json_output;
  63. }
  64. function getEventPicture($eventid)
  65. {
  66. $jsonurl = "https://graph.facebook.com/" . $eventid."/picture?type=large";
  67. return $jsonurl;
  68. }
  69. function getUserAlbums($userid)
  70. {
  71. $jsonurl = "https://graph.facebook.com/" . $userid."/albums";
  72. $jsonurl .= "?access_token=" . $_SESSION["access_token"];
  73. $json = file_get_contents($jsonurl,0,null,null);
  74. $json_output = json_decode($json);
  75. return $json_output;
  76. }
  77. function getAlbumPictures($albumid)
  78. {
  79. $jsonurl = "https://graph.facebook.com/" . $albumid."/photos";
  80. $jsonurl .= "?access_token=" . $_SESSION["access_token"];
  81. $json = file_get_contents($jsonurl,0,null,null);
  82. $json_output = json_decode($json);
  83. return $json_output;
  84. }
  85. function getUserEvents() {
  86. $jsonurl = "https://api.facebook.com/method/events.get";
  87. $jsonurl = $jsonurl . "?access_token=" . $_SESSION["access_token"];
  88. $jsonurl = $jsonurl . "&format=json";
  89. $json = file_get_contents($jsonurl,0,null,null);
  90. $json_output = json_decode($json);
  91. return $json_output;
  92. }
  93. function getEventUsers($eventid)
  94. {
  95. $jsonurl = "https://api.facebook.com/method/events.getMembers";
  96. $jsonurl = $jsonurl."?eid=".$eventid."&access_token=".$_SESSION["access_token"];
  97. $jsonurl = $jsonurl."&format=json";
  98. $json = file_get_contents($jsonurl, 0, null, null);
  99. $json_output = json_decode($json);
  100. return $json_output;
  101. }
  102. function getImageUrl($imageid) {
  103. $url = "https://graph.facebook.com/" . $imageid;
  104. $url = $url."?access_token=".$_SESSION["access_token"];
  105. $json = file_get_contents($url, 0, null, null);
  106. $jsonoutput = json_decode($json);
  107. return $jsonoutput->{"picture"};
  108. }
  109. function getUserImage($userid)
  110. {
  111. $url = "https://graph.facebook.com/" . $userid."/picture";
  112. return $url;
  113. }
  114. function printUser() {
  115. print_r($_SESSION["access_token"]);
  116. }
  117. function getUserImageUrl($userid) {
  118. return "https://graph.facebook.com/" . $userid . "/picture/";
  119. }