Facebook PHP SDK Issues -
i've been searching days solution. fist allow me paint out how methodology works process. below works great, unless, user doesn't authorize app origin when directed facebook. understand there cancel_url
paramater can use, directing them logout.php
page below doesn't if don't authorize app.
this public kiosk, logging user in , out critical. help appreciated. realize long post, wanted show doing during process.
user hits index.php
code @ top.
require 'facebook-sdk/src/facebook.php'; // create our application instance (replace appid , secret). $facebook = new facebook(array( 'appid' => 'xxx', 'secret' => 'xxx', )); $user = $facebook->getuser(); if ($user) { seek { // proceed knowing have logged in user who's authenticated. $user_profile = $facebook->api('/me'); } grab (facebookapiexception $e) { error_log($e); $user = null; } } // login or logout url needed depending on current user state. if ($user) { $logouturl = $facebook->getlogouturl(array( 'next' => ($fbconfig['baseurl'].'logout.php') )); } else { $loginurl = $facebook->getloginurl(array('scope' => 'publish_stream, email')); }
clicking on facebook share icon (i'm directing them $loginurl
page):
$("#facebook_service").click(function () { window.location = "<?php echo $loginurl; ?>"; });
when login facebook , redirected prompted modal box type , post wall. doing following.
<script> function sendfb(datastr){ $.ajax({ type: "get", url: "post.php", data: datastr, success: function(html){ alert("thank you, post published."); window.location = "<?php echo $logouturl; ?>" } }); } </script>
and here, post.php
page looks this:
require 'facebook-sdk/src/facebook.php'; $facebook = new facebook(array( 'appid' => 'xxx', 'secret' => 'xxx', )); if (isset($_get['post'])){ seek { $publishstream = $facebook->api("/$user/feed", 'post', array( 'message' => $_get['message'], 'link' => 'http://myurl.com', 'picture' => 'http://mypicture.jpg', 'name' => 'facebook text' ) ); } grab (facebookapiexception $e) { error_log($e); } }
you can see after ajax success call, user redirected logout url provided facebook, , clear session data, redirect them logout.php
has following...
require 'facebook-sdk/src/facebook.php'; // create our application instance (replace appid , secret). $facebook = new facebook(array( 'appid' => 'xxx', 'secret' => 'xxx', )); $facebook->destroysession(); setcookie('fbs_'.$facebook->getappid(), '', time()-100, '/', 'domain.com'); session_destroy(); header("location: index.php");
php facebook
No comments:
Post a Comment