Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If the user presses Allow, your app is authorized. The OAuth Dialog will redirect (via HTTP 302) the user's browser to the URL you passed in the redirect_uri parameter with an authorization code:</p> <pre><code>http://YOUR_URL?code=A_CODE_GENERATED_BY_SERVER </code></pre> <p>With this code in hand, you can proceed to the next step, app authentication, to gain the access token you need to make API calls.</p> <h2>Refer: <a href="https://developers.facebook.com/docs/authentication/" rel="nofollow">https://developers.facebook.com/docs/authentication/</a></h2> <p><strong>EDIT:</strong> Here's a sample of the authentication, this won't show ?code=Blabla.. First download the latest Facebook PHP SDK from here: <a href="https://github.com/facebook/php-sdk/tree/master/src" rel="nofollow">https://github.com/facebook/php-sdk/tree/master/src</a></p> <p>Make sure you save all 3 files, facebook.php, base_facebook.php and fb_ca_chain_bundle.crt Now replace the text "YOUR_APP_ID" and ""YOUR_APP_API_SECRET" with your Application ID and App Secret from facebook, I've added sample wall posting using graph api, if you don't want, you can remove it, if you go through my codes and comments, you'll understand what it does and you don't want to do anything to get access token, just use $access_token variable and it'll give you the access_token of the current user and if you want the user's ID then use $user variable, if you want user's basic information, use $userInfo variable and it'll fetch user's data using graph api and returns all information in an array, you'll get the current user's info like id,name,first_name,last_name,link,hometown,location,bio,work,education,gender,timezone.etc.</p> <p>Change $RedirectUrl with your landing page URL or your canvas page url</p> <pre><code> &lt;?php require 'facebook.php'; define('FACEBOOK_APP_ID', "YOUR_APP_ID"); // Your App ID define('FACEBOOK_SECRET', "YOUR_APP_API_SECRET"); // Your App API Secret $RedirectUrl = "http://apps.facebook.com/myapp/"; // Your Landing Page URL, User's will be redirect to this URL after they allow your app. function d($d){ echo "&lt;pre&gt;"; print_r($d); echo "&lt;/pre&gt;"; } $user = null; $facebook = new Facebook(array( 'appId' =&gt; FACEBOOK_APP_ID, 'secret' =&gt; FACEBOOK_SECRET, 'cookie' =&gt; true, )); $user = $facebook-&gt;getUser(); // Get the UID of the connected user, or 0 if the Facebook user is not connected. if(isset($_GET['code'])){ header("Location: $RedirectUrl"); } if($user == 0) { // If User is not connected to your app, then redirect User to Authentication Page. /** * Get a Login URL for use with redirects. By default, full page redirect is * assumed. If you are using the generated URL with a window.open() call in * JavaScript, you can pass in display=popup as part of the $params. * * The parameters: * - redirect_uri: the url to go to after a successful login * - scope: comma separated list of requested extended perms */ $login_url = $facebook-&gt;getLoginUrl($params = array('scope' =&gt; "publish_stream", 'redirect_uri' =&gt; $RedirectUrl)); echo("&lt;script&gt; top.location.href='" . $login_url . "'&lt;/script&gt;"); } else { // If User is connected to your app, then do something. $signed_request = $facebook-&gt;getSignedRequest(); // Get the data from a signed_request token. $access_token = $facebook-&gt;getAccessToken(); // Determines the access token that should be used for API calls. $userInfo = $facebook-&gt;api("/me"); // Get's User Info try { // Posts to user's wall after the user allows your app. $wallpost = array( 'message' =&gt; "I like this", 'link' =&gt; 'http://google.com', 'picture' =&gt; 'http://i.imgur.com/8iz6L.png', 'name' =&gt; 'This is cool', 'description'=&gt; 'Checkout this cool app' ); $publishStream = $facebook-&gt;api("/$user/feed", "post", $wallpost); // WallPost to User's Wall using Graph API echo "Your post was successfully posted to UID: $user"; } catch (FacebookApiException $e) { d($e); } } ?&gt; </code></pre>
 

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