Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2012
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. <?php
  2. include "config.php";
  3.  
  4. //Get Return from FB
  5. $code = $_GET["code"];
  6. $error_reason = $_GET["error_reason"];
  7. $error = $_GET["error"];
  8. $error_description = $_GET["error_description"];
  9.  
  10. if( $error_reason != "" && $error != "" && $error_description != "" ) {
  11. echo "<h1>" . $error_reason . "</h1>";
  12. echo "<p>" . $error_description . "</p>";
  13. exit();
  14. }
  15. else if( $code == "" ) {
  16. echo "<h1>Unknown Error</h1>";
  17. echo "<p>Facebook did not properly authenticate you. Please try again.</p>";
  18. exit();
  19. }
  20. else {
  21. $fb_return_page = $url_app_location."auth.php";
  22.  
  23. $fb_auth_page = "https://graph.facebook.com/oauth/access_token?client_id=" . $app_id .
  24. "&redirect_uri=" . $fb_return_page .
  25. "&client_secret=" . $app_secret .
  26. "&code=" . $code;
  27.  
  28.  
  29.  
  30. $ch = curl_init();
  31. curl_setopt( $ch, CURLOPT_URL, $fb_auth_page );
  32. curl_setopt( $ch, CURLOPT_HEADER, 0 );
  33. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  34. curl_setopt( $ch, CURLOPT_TIMEOUT, 30 );
  35. $fb_oauth_token = curl_exec( $ch );
  36. curl_close( $ch );
  37.  
  38. parse_str( $fb_oauth_token, $fb_oauth_arr );
  39.  
  40. if( ! $fb_oauth_arr["access_token"] ) {
  41. echo "<h1>Unknown Error</h1>";
  42. echo "<p>Facebook did not return authentication token. Please try again.</p>";
  43. exit();
  44. }
  45.  
  46. $access_token = $fb_oauth_arr["access_token"];
  47.  
  48. //Post to facebook wall
  49. $fb_post_page = "https://graph.facebook.com/me/feed?access_token=" . $access_token;
  50. $message_text = "Appia just updated my status.";
  51. $fb_message = "message=".$message_text;
  52.  
  53. $ch = curl_init();
  54. curl_setopt( $ch, CURLOPT_URL, $fb_post_page );
  55. curl_setopt( $ch, CURLOPT_HEADER, 0 );
  56. curl_setopt( $ch, CURLOPT_POST, true );
  57. curl_setopt( $ch, CURLOPT_POSTFIELDS, $fb_message );
  58. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  59. curl_setopt( $ch, CURLOPT_TIMEOUT, 30 );
  60. $fb_message_return = curl_exec( $ch );
  61. curl_close( $ch );
  62.  
  63. echo "Message Posted to Facebook";
  64. }
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement