PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 26, 2022

[FIXED] Difficulty authorizing app in Facebook-PHP-SDK

 February 26, 2022     facebook-php-sdk, php     No comments   

Issue

I am struggling to authorize my app in Facebook-PHP-SDK. The sample code I got form this link, https://developers.facebook.com/docs/php/howto/example_access_token_from_canvas, is a simple piece of code to get an access token but I cannot get my access token to access any data from Facebook through my code because I do not know how to authorize it. One problem might be I have not finished the setup of Facebook Login as seen in the screenshot below. Could that be what is causing the problem? Code and error message below too. Note: I have omitted my app id and secret for security reasons.

App

PHP Code

<?php
require_once(__DIR__ . '/vendor/autoload.php');
$app_id = "";
$app_secret ="";
$fb = new Facebook\Facebook([
        'app_id' => '{$app_id}',
        'app_secret' => '{$app_secret}',
        'persistent_data_handler' => 'memory',
        'default_graph_version' => 'v3.3',
]);

$helper = $fb->getCanvasHelper();
try {
        $accessToken = $helper->getAccessToken();
}
catch(Facebook\Exceptions\FacebookResponseException $e) {
        // When Graph returns an error
        echo 'Graph returned an error: ' . $e->getMessage();
        exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
        // When validation fails or other local issues
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
        exit;
}

        echo 'No OAuth data could be obtained from the signed request. User has not authorized your app yet.';
        exit;
}
// Logged in
echo '<h3>Signed Request</h3>';
var_dump($helper->getSignedRequest());

echo '<h3>Access Token</h3>';
var_dump($accessToken->getValue());

Error Message

No OAuth data could be obtained from the signed request. User has not authorized your app yet.

Solution

You must login and authorize your application before to get the token, you must have a login page and the redirect page to fetch the token. check this link, because you must start by this: example login FB

Have Fun :)



Answered By - Soufiane Lamnizeh
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing