Sourav_5 0 Newbie Poster

Hi guys, this is my first post here.
I built Fb app around 2010 and then it was much easy to get started. But after 6 years I am starting again to develop my 1st app after tha gap. But now it's been hard, as I need HTTPS for the hosting.
So I set my WAMP server to have SSL with OpenSSL and now can open the localhost with https though it shows a warning that the certificate is not trusted.

I'm asking you guys to show me copy-paste ready Fb app built on PHP just to show the User name if he is logged in, else show a login link and show the user name after the user logs in.
Thanks :)

Here is my non-working app code in PHP

<?php
session_start();
require_once __DIR__ . '/fbsdk/autoload.php';

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

$helper = $fb->getCanvasHelper();
$permissions = ['email']; 

try {
    if (isset($_SESSION['facebook_access_token'])) {
    $accessToken = $_SESSION['facebook_access_token'];
    } else {
        $accessToken = $helper->getAccessToken();
    }
} catch(Facebook\Exceptions\FacebookResponseException $e) {
} catch(Facebook\Exceptions\FacebookSDKException $e) {
 }

if (isset($accessToken)) {
    if (isset($_SESSION['facebook_access_token'])) {
        $fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
    } else {
        $_SESSION['facebook_access_token'] = (string) $accessToken;
        $oAuth2Client = $fb->getOAuth2Client();
        $longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($_SESSION['facebook_access_token']);
        $_SESSION['facebook_access_token'] = (string) $longLivedAccessToken;
        $fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
    }

    try {
        $request = $fb->get('/me');
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
        if ($e->getCode() == 190) {
            unset($_SESSION['facebook_access_token']);
            $helper = $fb->getRedirectLoginHelper();
            $loginUrl = $helper->getLoginUrl('https://apps.facebook.com/NAMESPACE/', $permissions);
            echo "<script>window.top.location.href='".$loginUrl."'</script>";
            exit;
        }
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
    }

    try {
        $requestPicture = $fb->get('/me/picture?redirect=false&height=300'); 
        $requestProfile = $fb->get('/me'); // getting basic info
        $picture = $requestPicture->getGraphUser();
        $profile = $requestProfile->getGraphUser();
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
    }
?>

And the error I get
*Uncaught exception 'Facebook\Exceptions\FacebookSDKException' with message 'Signed request has an invalid signature.
Signed request has an invalid signature. *

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.