Advertisement
Guest User

Untitled

a guest
Mar 17th, 2011
1,090
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.57 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'fb.php';
  4.  
  5. $pageId = "XXXXXXXXXXXXXXXXXXX";
  6.  
  7.  
  8. define('API_SECRET', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
  9.  
  10. $baseurl = "http://example.com";
  11.  
  12. $facebook = new Facebook(array(
  13.     'appId'  => 'XXXXXXXXXXXXXXXXXX',
  14.     'secret' => API_SECRET,
  15.     'cookie' => true,
  16.     'fileUpload' => true
  17. ));
  18.  
  19. $session = $facebook->getSession();
  20.  
  21. $me = null;
  22.  
  23. // Session based API call.
  24. if ($session) {
  25.     $uid = $facebook->getUser();
  26. //  $me = $facebook->api('/me');
  27.     $me = $facebook->api("/$pageId");
  28. }
  29.  
  30. if ($me) {
  31.     $logoutMe = $facebook->getLogoutUrl(array('next' => $base_url));
  32. } else {
  33.     $loginMe =  $loginUrl = $facebook->getLoginUrl(array(
  34.         'display'   => 'popup',
  35.         'next'      => $baseurl /*. '?loginsucc=1'*/,
  36. //      'cancel_url'=> $baseurl . '?cancel=1',
  37.         'req_perms' => 'create_event'
  38.     ));
  39. }
  40.  
  41. // if user click cancel in the popup window
  42. if ($me && empty($_GET['session']) && empty($_COOKIE['fbs_' . API_SECRET])) {
  43.     die("<script>window.close();</script>");
  44. } elseif($me && !empty($_GET['session'])) {
  45.     //only if valid session found and loginsucc is set,
  46.     //after facebook redirects it will send a session parameter as a json value
  47.     //now decode them, make them array and sort based on keys
  48.     $sortArray = get_object_vars(json_decode($_GET['session']));
  49.     ksort($sortArray);
  50.     $strCookie  =   "";
  51.     $flag       =   false;
  52.     foreach($sortArray as $key=>$item){
  53.         if ($flag) $strCookie .= '&';
  54.         $strCookie .= $key . '=' . $item;
  55.         $flag = true;
  56.     }
  57.  
  58.     //now set the cookie so that next time user don't need to click login again
  59.     setCookie('fbs_' . API_SECRET, $strCookie);
  60.  
  61.     die("<script>window.close();window.opener.location.reload();</script>");
  62. }
  63.  
  64. if ($me) {
  65.     var_dump($me);
  66.     //Path to photo (only tested with relative path to same directory)
  67. //  $file = "end300.jpg";
  68.     //The event information array (timestamps are "Facebook time"...)
  69.     $time = time() + rand(1, 100) * rand(24, 64) * 3600;
  70.     $event_info = array(
  71.         "privacy_type" => "SECRET",
  72. //      "name" => "Event Title "  . time(),
  73.         "name" => "Test Event Title "  . time(),
  74.         "host" => "Me ",
  75.         "start_time" => $time,
  76.         "end_time" => $time + 120,
  77.         "location" => "London " . time(),
  78.         "description" => "Event Description " . time()
  79.     );
  80.     //The key part - The path to the file with the CURL syntax
  81. //  $event_info[basename($file)] = '@' . realpath($file);
  82.     //Make the call - returns the event ID
  83. //  var_dump($facebook->api('me/events','post',$event_info));
  84.     var_dump($facebook->api("$pageId/events", 'post', $event_info));
  85. ?>
  86. <a href="<?= $facebook->getLogoutUrl() ?>">Logout</a>
  87. <?
  88. } else { ?>
  89. <script type="text/javascript">
  90.     var newwindow;
  91.     var intId;
  92.     function login(){
  93.         var  screenX    = typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft,
  94.             screenY    = typeof window.screenY != 'undefined' ? window.screenY : window.screenTop,
  95.             outerWidth = typeof window.outerWidth != 'undefined' ? window.outerWidth : document.body.clientWidth,
  96.             outerHeight = typeof window.outerHeight != 'undefined' ? window.outerHeight : (document.body.clientHeight - 22),
  97.             width    = 500,
  98.             height   = 270,
  99.             left     = parseInt(screenX + ((outerWidth - width) / 2), 10),
  100.             top      = parseInt(screenY + ((outerHeight - height) / 2.5), 10),
  101.             features = (
  102.             'width=' + width +
  103.             ',height=' + height +
  104.             ',left=' + left +
  105.             ',top=' + top
  106.             );
  107.         newwindow=window.open('<?=$loginUrl?>','Login by facebook',features);
  108.         if (window.focus) {newwindow.focus()}
  109.         return false;
  110.     }
  111. </script>
  112. Please login to Facebook and we will setup the event for you! <br />
  113. <a href="#" onclick="login();return false;">
  114.     <img src="http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif" border="0">
  115. </a>
  116. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement