Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is my answer. Above code does not work for me. But I made one for myself, that works perfectly. Here is the code.</p> <p>Code for server side:</p> <pre class="lang-php prettyprint-override"><code>&lt;?php @session_start(); require "fblib/facebook.php"; define('YOUR_APP_ID',''); define('YOUR_APP_SECRET',''); $facebook = new Facebook(array( 'appId' =&gt; YOUR_APP_ID, 'secret' =&gt; YOUR_APP_SECRET, )); if($_SESSION['access_token']!='') { $access_token = $_SESSION['access_token']; $user_id = $_SESSION['user_id']; } else { $access_token = $_REQUEST['access_token']; $_SESSION['access_token'] = $_REQUEST['access_token']; $user_id = $_REQUEST['user_id']; $_SESSION['user_id'] = $_REQUEST['user_id']; } $user_id = $_REQUEST['user_id']; $facebook-&gt;setAccessToken($_REQUEST['access_token']); $post = array( 'message' =&gt; 'This message is posted with access token - ' . date('Y-m-d H:i:s') ); // and make the request $response = $facebook-&gt;api('/me/feed', 'POST', $post); ?&gt; </code></pre> <p>Code for client side:</p> <pre class="lang-php prettyprint-override"><code>&lt;?php require "fblib/facebook.php"; define('YOUR_APP_ID','387647494631464'); define('YOUR_APP_SECRET','857f41bdd23c26ae132a1c75a343ddc9'); $facebook = new Facebook(array( 'appId' =&gt; YOUR_APP_ID, 'secret' =&gt; YOUR_APP_SECRET, )); $user = $facebook-&gt;getUser(); if ($user) { try { $user_profile = $facebook-&gt;api('/me'); } catch (FacebookApiException $e) { // The access token we have is not valid $user = null; } } ?&gt; &lt;div id="fb-root"&gt;&lt;/div&gt; &lt;script language="javascript" src="js/jquery-1.7.2.min.js"&gt;&lt;/script&gt; &lt;script&gt; var accessToken; var uid; // Load the SDK Asynchronously (function(d){ var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; if (d.getElementById(id)) { return; } js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; ref.parentNode.insertBefore(js, ref); }(document)); // Init the SDK upon load window.fbAsyncInit = function() { FB.init({ appId : '', // App ID channelUrl : '//'+window.location.hostname+'/channel', // Path to your Channel File status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : true // parse XFBML }); // listen for and handle auth.statusChange events FB.Event.subscribe('auth.statusChange', function(response) { if (response.authResponse) { // user has auth'd your app and is logged into Facebook FB.api('/me', function(me) { if (me.name) { // document.getElementById('auth-displayname').innerHTML = me.name; accessToken = response.authResponse.accessToken; uid = response.authResponse.userID; } }) // document.getElementById('auth-loggedout').style.display = 'none'; // document.getElementById('auth-loggedin').style.display = 'block'; } else { // user has not auth'd your app, or is not logged into Facebook // document.getElementById('auth-loggedout').style.display = 'block'; // document.getElementById('auth-loggedin').style.display = 'none'; } }); // respond to clicks on the login and logout links document.getElementById('auth-loginlink').addEventListener('click', function() { // FB.login(); FB.login(function(response) { // handle the response }, {scope: 'offline_access,publish_stream'}); }); } function gettoken() { // alert("User Token :"+accessToken+", User id :"+uid); $.post('fbpost.php',{access_token:accessToken,user_id:uid},function(data) { // alert(data); }); } &lt;/script&gt; &lt;?php if (!$user): ?&gt; &lt;a href="Javascript:void(0)" id="auth-loginlink"&gt;Login with Facebook&lt;/a&gt; &lt;?php else: ?&gt; &lt;a href="Javascript:void(0)" id="auth-logoutlink" onClick="FB.logout()" &gt;Logout from Facebook&lt;/a&gt; &lt;?php endif ?&gt; &lt;a href="Javascript:void(0)" onclick="gettoken()" &gt;Post Into Wall&lt;/a&gt; </code></pre> <p>Please disable "Remove offline_access permission:" from fb apps advance setting. by selecting disable radio button.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload