Advertisement
Guest User

Untitled

a guest
Oct 16th, 2013
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.48 KB | None | 0 0
  1. <?php
  2. require 'facebook.php';
  3.  
  4. $app_id = "170492669817549";
  5. $app_secret = "cdd71487083b01edab8946d417e4aede";
  6. $my_url = "http://facebook.faver.be/facebook/event.php";
  7. $event_id = "146849958858256";
  8. $rsvp_status = "";
  9.  
  10. $code = $_REQUEST["code"];
  11.  
  12. if(empty($code)) {
  13.     $auth_url = "http://www.facebook.com/dialog/oauth?client_id="
  14.     . $app_id . "&redirect_uri=" . urlencode($my_url)
  15.     . "&scope=rsvp_event";
  16.     echo("<script>top.location.href='" . $auth_url . "'</script>");
  17. }
  18.  
  19. $token_url = "https://graph.facebook.com/oauth/access_token?client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret=" . $app_secret . "&code=" . $code;
  20.    
  21. $access_token = file_get_contents($token_url);
  22.  
  23.  
  24. if( isset($_POST['rsvp']) ) {
  25.     // Form submitted, call the Graph API to RSVP to the event
  26.     echo $access_token;
  27.     $event_rsvp = "https://graph.facebook.com/$event_id/{$_POST['rsvp']}?method=post&" . $access_token;
  28.     $rsvped = json_decode(file_get_contents($event_rsvp));
  29.     if($rsvped) {
  30.         $msg = "Your RSVP status is now <strong>{$_POST['rsvp']}</strong>";
  31.         $rsvp_status = $_POST['rsvp'];
  32.     }
  33. }
  34. if( !$rsvp_status ) {
  35.     $query = "SELECT rsvp_status FROM event_member WHERE eid=$event_id AND uid=me()";
  36.     $fql_url = "https://api.facebook.com/method/fql.query?"
  37.         . "query=" . urlencode($query)
  38.         . "&format=json"
  39.         . "&" . $access_token;
  40.     $fql_resp = json_decode(file_get_contents($fql_url));
  41.     $rsvp_status = $fql_resp[0]->rsvp_status;
  42. }
  43. ?>
  44. <!doctype html>
  45. <html>
  46. <head>
  47. <title>Create An Event</title>
  48. <style>
  49. label {float: left; width: 100px;}
  50. input[type=text],textarea {width: 210px;}
  51. #msg {border: 1px solid #000; padding: 5px; color: red;}
  52. </style>
  53. </head>
  54. <body>
  55. <?php if( isset($msg) ) { ?>
  56. <p id="msg"><?php echo $msg; ?></p>
  57. <?php } ?>
  58. <form action="" method="post">
  59.     <p>
  60.         <label for="privacy_type">RSVP:</label>
  61.         <input type="radio" name="rsvp" value="attending" <?php if($rsvp_status==="attending") echo "checked='checked'"; ?>/>Attending&nbsp;&nbsp;&nbsp;
  62.         <input type="radio" name="rsvp" value="maybe" <?php if($rsvp_status==="maybe" || $rsvp_status==="unsure") echo "checked='checked'"; ?>/>Maybe&nbsp;&nbsp;&nbsp;
  63.         <input type="radio" name="rsvp" value="declined" <?php if($rsvp_status==="declined") echo "checked='checked'"; ?>/>Not Attending&nbsp;&nbsp;&nbsp;
  64.     </p>
  65.     <p><input type="submit" value="RSVP to this event" /></p>
  66. </form>
  67. </body>
  68. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement