Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include "config.php";
- //Get Return from FB
- $code = $_GET["code"];
- $error_reason = $_GET["error_reason"];
- $error = $_GET["error"];
- $error_description = $_GET["error_description"];
- if( $error_reason != "" && $error != "" && $error_description != "" ) {
- echo "<h1>" . $error_reason . "</h1>";
- echo "<p>" . $error_description . "</p>";
- exit();
- }
- else if( $code == "" ) {
- echo "<h1>Unknown Error</h1>";
- echo "<p>Facebook did not properly authenticate you. Please try again.</p>";
- exit();
- }
- else {
- $fb_return_page = $url_app_location."auth.php";
- $fb_auth_page = "https://graph.facebook.com/oauth/access_token?client_id=" . $app_id .
- "&redirect_uri=" . $fb_return_page .
- "&client_secret=" . $app_secret .
- "&code=" . $code;
- $ch = curl_init();
- curl_setopt( $ch, CURLOPT_URL, $fb_auth_page );
- curl_setopt( $ch, CURLOPT_HEADER, 0 );
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- curl_setopt( $ch, CURLOPT_TIMEOUT, 30 );
- $fb_oauth_token = curl_exec( $ch );
- curl_close( $ch );
- parse_str( $fb_oauth_token, $fb_oauth_arr );
- if( ! $fb_oauth_arr["access_token"] ) {
- echo "<h1>Unknown Error</h1>";
- echo "<p>Facebook did not return authentication token. Please try again.</p>";
- exit();
- }
- $access_token = $fb_oauth_arr["access_token"];
- //Post to facebook wall
- $fb_post_page = "https://graph.facebook.com/me/feed?access_token=" . $access_token;
- $message_text = "Appia just updated my status.";
- $fb_message = "message=".$message_text;
- $ch = curl_init();
- curl_setopt( $ch, CURLOPT_URL, $fb_post_page );
- curl_setopt( $ch, CURLOPT_HEADER, 0 );
- curl_setopt( $ch, CURLOPT_POST, true );
- curl_setopt( $ch, CURLOPT_POSTFIELDS, $fb_message );
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- curl_setopt( $ch, CURLOPT_TIMEOUT, 30 );
- $fb_message_return = curl_exec( $ch );
- curl_close( $ch );
- echo "Message Posted to Facebook";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement