Advertisement
lpuarmy

FB Connect kyu-lpfi

Sep 13th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. <?php
  2. $KyuFB = array();
  3. $KyuFB['appId'] = 'App ID'; // Isi dengan App ID/API Key punya agan
  4. $KyuFB['secret'] = 'App Secret'; // Isi dengan App Secret punya agan
  5. $KyuFB['baseurl'] = 'http://kyu.16mb.com/fb'; // Isi dengan Canvas URL punya agan (misal: http://domaintc.com/fb)
  6. $KyuFB['cookie'] = true; // optional
  7.  
  8. try
  9. {
  10. include_once "common/facebook.php";
  11. }
  12. catch(Exception $e)
  13. {
  14. error_log($e);
  15. }
  16.  
  17. // membuat class berdasarkan array
  18. $facebook = new Facebook($KyuFB);
  19.  
  20. // mendapatkan info user
  21. $user = $facebook->getUser();
  22.  
  23. // membuat login url
  24. $loginUrl = $facebook->getLoginUrl(array(
  25. 'scope' => 'email,user_birthday,publish_stream,offline_access,read_stream,user_photos,status_update',
  26. 'redirect_uri' => $KyuFB['baseurl'],
  27. 'display' => 'touch'
  28. ));
  29.  
  30. // membuat logout url
  31. $logoutUrl = $facebook->getLogoutUrl();
  32. if ($user)
  33. {
  34. try
  35. {
  36. // Proceed knowing you have a logged in user who's authenticated.
  37. $userdata = $facebook->api('/me');
  38. $user_name = $userdata['name'];
  39. $KyuFBlink = $userdata['link'];
  40. $KyuFBusername = $userdata['username'];
  41. $KyuFBpic = "http://graph.facebook.com/".$user."/picture";
  42. $KyuFBbirth = $userdata['birthday'];
  43. $KyuFBgender = $userdata['gender'];
  44. }
  45. catch(FacebookApiException $e)
  46. {
  47. error_log($e);
  48. $user_id = NULL;
  49. }
  50. }
  51.  
  52. ?>
  53.  
  54. // ini kalau LPFI
  55.  
  56. <?php
  57. $lpfiFB = array();
  58. $lpfiFB['appId'] = 'App ID'; // Isi dengan App ID/API Key punya agan
  59. $lpfiFB['secret'] = 'App Secret'; // Isi dengan App Secret punya agan
  60. $lpfiFB['baseurl'] = 'http://twit.lpfisite.com/fb'; // Isi dengan Canvas URL punya agan (misal: http://domaintc.com/fb)
  61. $lpfiFB['cookie'] = true; // optional
  62.  
  63. try
  64. {
  65. include_once "common/facebook.php"; // letak file facebook.php
  66. }
  67. catch(Exception $e)
  68. {
  69. error_log($e);
  70. }
  71.  
  72. // membuat class berdasarkan array
  73. $facebook = new Facebook($KyuFB);
  74.  
  75. // mendapatkan info user
  76. $user = $facebook->getUser();
  77.  
  78. // membuat login url
  79. $loginUrl = $facebook->getLoginUrl(array(
  80. 'scope' => 'email,user_birthday,publish_stream,offline_access,read_stream,user_photos,status_update',
  81. 'redirect_uri' => $KyuFB['baseurl'],
  82. 'display' => 'touch'
  83. ));
  84.  
  85. // membuat logout url
  86. $logoutUrl = $facebook->getLogoutUrl();
  87. if ($user)
  88. {
  89. try
  90. {
  91. // Proceed knowing you have a logged in user who's authenticated.
  92. $userdata = $facebook->api('/me');
  93. $user_name = $userdata['name'];
  94. $lpfiFBlink = $userdata['link'];
  95. $lpfiFBusername = $userdata['username'];
  96. $lpfiFBpic = "http://graph.facebook.com/".$user."/picture";
  97. $lpfiFBbirth = $userdata['birthday'];
  98. $lpfiFBgender = $userdata['gender'];
  99. }
  100. catch(FacebookApiException $e)
  101. {
  102. error_log($e);
  103. $user_id = NULL;
  104. }
  105. }
  106.  
  107. ?>
  108.  
  109. <?php
  110. // function fb_logout di twitter.php
  111.  
  112. function fb_logout(){
  113. include_once "common/fbconfig.php";
  114.  
  115. $facebook = new Facebook($lpfiFB);
  116. unset($_SESSION['fb_' . $facebook->getAppId() . '_code']);
  117. unset($_SESSION['fb_' . $facebook->getAppId() . '_access_token']);
  118. unset($_SESSION['fb_' . $facebook->getAppId() . '_user_id']);
  119. header('Location: '. $facebook->getLogoutUrl(array('next' => $lpfiFB['baseurl'])));
  120. die();
  121. theme('page', "FB Connect Logout", $content);
  122. }
  123.  
  124. // function fb_connect di twitter.php
  125. function fb_connect() {
  126. include_once 'common/fbconfig.php';
  127.  
  128. if (!$user)
  129. {
  130. $content .= '<div style="padding:5px;"><fieldset><legend>FB Connect</legend>';
  131. $content .= 'Connect your Facebook Account with Kyuweet<br />';
  132. $content .= '<a href="'.$loginUrl.'"><img src="http://kyu.16mb.com/images/fbconnect.png" alt="Connect your Facebook Account with LPFI Twit" title="Connect your Facebook Account with LPFI Twit" width="89" height="20"/></a>';
  133. $content .= '</div>';
  134. }
  135. else
  136. {
  137. $content .= '<div style="padding:5px;"><fieldset><legend>FB Connect</legend>';
  138. $content .= 'Hey, <a href="http://m.facebook.com/profile.php?id='.$user.'" target="_blank">'.$user_name.'</a>, Now, your Facebook account is connected with LPFI Twit<br />';
  139. $content .= '<fieldset><legend>User Information</legend><table width="auto" border="0">
  140. <tr>
  141. <td width="89" rowspan="4" valign="top"><a href="'.$lpfiFBlink.'" target="_blank"><img src="'. $lpfiFBpic . '" /></a></td>
  142. <td width="78">Username :</td>
  143. <td width="238">'. $lpfiFBusername . '</td>
  144. </tr>
  145. <tr>
  146. <td>Name :</td>
  147. <td>'. $user_name . '</td>
  148. </tr>
  149. <tr>
  150. <td>Gender :</td>
  151. <td>'. $lpfiFBgender . '</td>
  152. </tr>
  153. <tr>
  154. <td>Birthday :</td>
  155. <td>'. $lpfiFBbirth . '</td>
  156. </tr>
  157. </table></fieldset><br /><br />';
  158. $content .= '<a href="fblogout" title="Disconnect your Facebook Account" style="padding:2px 5px; background-color:#019AD2; color:#fff;">Disconnect your Facebook Account</a>';
  159. $content .= '</div>';
  160. }
  161.  
  162. theme('page', 'FB Connect', $content);
  163. }
  164. ?>
  165.  
  166. - yufex
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement