Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require_once('lib/fb/facebook.php');
- $config = array(
- 'appId' => 'XXX',
- 'secret' => 'XXX',
- );
- $facebook = new Facebook($config);
- $user_id=$facebook->getUser();
- if($user_id) {
- // We have a user ID, so probably a logged in user.
- // If not, we'll get an exception, which we handle below.
- try {
- $ret_obj = $facebook->api('/me/feed', 'POST',
- array(
- 'link' => $link,
- 'message' => $title
- ));
- $output.= 'Article successfully submitted to Facebook!<br/> Post ID: ' . $ret_obj['id'];
- } catch(FacebookApiException $e) {
- // If the user is logged out, you can have a
- // user ID even though the access token is invalid.
- // In this case, we'll get an exception, so we'll
- // just ask the user to login again here.
- $login_url = $facebook->getLoginUrl( array(
- 'scope' => 'publish_stream'
- ));
- $output.= 'Please <a href="' . $login_url . '">login.</a>';
- error_log($e->getType());
- error_log($e->getMessage());
- }
- // Give the user a logout link
- //echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
- } else {
- // No user, so print a link for the user to login
- // To post to a user's wall, we need publish_stream permission
- // We'll use the current URL as the redirect_uri, so we don't
- // need to specify it here.
- $login_url = $facebook->getLoginUrl( array( 'scope' => 'publish_stream' ) );
- $output.= 'Please <a href="' . $login_url . '">login.</a>';
- }
- }
- else {$output.= "An error has occurred";}
- echo $output;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement