Advertisement
Guest User

Untitled

a guest
Feb 25th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.  
  4. require 'sdk/facebook.php';
  5.  
  6. // Write your AppID and AppSecret
  7. $facebook = new Facebook(array(
  8.   'appId'  => 'XXXXXXX',
  9.   'secret' => 'XXXXXXX',
  10. ));
  11.  
  12.  
  13. $user = $facebook->getUser();
  14. if ($user) {
  15.   try {
  16.     $user_profile = $facebook->api('/me');
  17.   } catch (FacebookApiException $e) {
  18.     error_log($e);
  19.     $user = null;
  20.   }
  21. }
  22.  
  23. if ($user) {
  24.   $logoutUrl = $facebook->getLogoutUrl();
  25. } else {
  26.   $loginUrl = $facebook->getLoginUrl(   array(
  27.        'scope' => 'publish_stream,manage_pages'
  28.       ));
  29. }
  30.  
  31. ?>
  32. <!doctype html>
  33. <html>
  34.   <head>
  35.     <title>Publicar en Facebook</title>
  36.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  37.     <meta name="description" content="" />
  38.   </head>
  39.   <body>
  40.     <h1>Post to Friend's Wall</h1>
  41.  
  42.     <div id="loginWrapper">
  43.     <?php if ($user): ?>
  44.       <a href="<?php echo $logoutUrl; ?>">Logout</a>
  45.     <?php else: ?>
  46.         <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
  47.     <?php endif ?>
  48.     </div>
  49.    
  50.  
  51.     <?php if ($user){
  52.  
  53.         $user_friends = $facebook->api('/me/friends');
  54.         sort($user_friends['data']);
  55.  
  56.         $user_friends2 = $facebook->api('/me/accounts');
  57.         sort($user_friends2['data']);
  58.  
  59.        
  60.         if(isset($_POST['submit'])) {
  61.             $sendTo = $_POST['friend'];
  62.             $link = $_POST['link'];
  63.             $message = $_POST['message'];
  64.            
  65.             // all options: http://stackoverflow.com/questions/691425/how-do-you-post-to-the-wall-on-a-facebook-page-not-profile
  66.             $attachment = array('message' => $message, 'link' => $link );
  67.            
  68.             if($result = $facebook->api("/$sendTo/feed/",'post', $attachment)) {
  69.                 $feedbackMessage = "Message sent to friend $sendTo";
  70.             } else {
  71.                 $feedbackMessage = "Oops something went wrong";
  72.             }
  73.         }
  74.  
  75.  
  76.     ?>
  77.    
  78.         <form id="selectFriend" name="selectFriend" method="post">
  79.             <label for="Friend">Friend:</label>
  80.             <select id="friend" name="friend">
  81.                 <?php
  82.                 foreach($user_friends['data'] as $f){
  83.                     echo '<option value="'.$f['id'].'">'.$f['name'] .'</option>';
  84.                 }
  85.                 ?>
  86.             </select>
  87.             <label for="URL">URL:</label>
  88.             <input id="link" name="link">
  89.             <label for="Message">Message:</label>
  90.             <textarea id="message" name="message"></textarea>
  91.             <input type="submit" name="submit" id="submit" value="Send!">
  92.         </form>
  93.        
  94.  
  95.        
  96.         <?php
  97.         if(isset($feedbackMessage)) echo $feedbackMessage;
  98.         ?>
  99.    
  100.     <?php } ?>
  101.    
  102.   </body>
  103. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement