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

Saturday, February 26, 2022

[FIXED] How do I authorize a app in Facebook-PHP-SDK

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

Issue

Very new to PHP and downloaded Facebook-PHP-SDK and I am trying to run a simple code I found online but I keep getting an error. I have done lots of research on the problem, looked at similar questions on here and so for but have not been able to find anything that helps. It looks like I still need to authorize the app I created in Facebook Developers, but I cannot figure out how to do that.

<?php
require_once(__DIR__ . '/vendor/autoload.php');
$fb = new Facebook\Facebook([
  'app_id' => '{}',
  '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;
}

if (! isset($accessToken)) {
  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 are not supplying the SDK with the required app_id and app_secret so it can't do anything. That's why it gives you an OAUTH error. (fb-docs)

$fb = new Facebook\Facebook([
  'app_id' => '{}', // Here
  'app_secret' => '{}', // Here
  'persistent_data_handler' => 'memory',
  'default_graph_version' => 'v3.3',
  ]);

You need to get that data from your facebook app configuration dashboard. And plug into this object.

example:

$app_id = "1234";
$app_secret = "foobar";
$fb = new Facebook\Facebook([
  'app_id' => '{$app_id}',
  'app_secret' => '{$app_secret}',
  'default_graph_version' => 'v3.2',
  ]);


Answered By - aviya.developer
  • 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