Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2015
    Messaggi
    8

    Login Facebook: Errore "Facebook SDK returned an error: No URL set!"

    Buonasera a tutti, sto cercando di implementare l'accesso al nostro sito mediante sdk di Facebook, non riesco a risolvere la configurazione degli script, ottengo sempre il seguente errore (Facebook SDK returned an error: No URL set!)
    Premesso che il codice che uso funziona in un'altro sito di test (ovviamente con un'app facebook diversa).

    Questo e' il codice index.php dove appare il pulsante per il login e il richiamo dell'sdk, per ovvi motivi di sicurezza ho inserito xxxx al posto del nome del sito e ad altri dati sensibili.

    La classe User.php e incaricata alla gestione dell'utente e non credo interessi alla discusione, mentre quello che e' importante e' la parte di fbConfig.php

    Nel pannello di configurazione dell'app facebook

    URI di reindirizzamento OAuth validi

    http://xxxx.altervista.org/ e http://xxxx.altervista.org/fbapp0/

    Ripeto: questi due script copiati con la cartella sdk facebook in un altro sito funzionano benissimo .
    Grazie in anticipo per le risposte, un saluto

    [CODE]
    // index.php
    require_once 'fbConfig.php';
    require_once 'User.php';

    if(isset($accessToken)){
    if(isset($_SESSION['facebook_access_token'])){
    $fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
    }else{
    // Put short-lived access token in session
    $_SESSION['facebook_access_token'] = (string) $accessToken;

    // OAuth 2.0 client handler helps to manage access tokens
    $oAuth2Client = $fb->getOAuth2Client();

    // Exchanges a short-lived access token for a long-lived one
    $longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($_SESSION['facebook_access_token']);
    $_SESSION['facebook_access_token'] = (string) $longLivedAccessToken;

    // Set default access token to be used in script
    $fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
    }

    // Redirect the user back to the same page if url has "code" parameter in query string
    if(isset($_GET['code'])){
    header('Location: ./');
    }

    // Getting user facebook profile info
    try {
    $profileRequest = $fb->get('/me?fields=name,first_name,last_name,email,link,gen der,locale,picture');
    $fbUserProfile = $profileRequest->getGraphNode()->asArray();
    } catch(FacebookResponseException $e) {
    echo 'Graph returned an error: ' . $e->getMessage();
    session_destroy();
    // Redirect user back to app login page
    header("Location: ./");
    exit;
    } catch(FacebookSDKException $e) {
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
    }

    // Initialize User class
    /* ---------------------- PARTE DB ------------------------*/

    $user = new User();

    // Insert or update user data to the database
    $fbUserData = array(
    'oauth_provider'=> 'facebook',
    'oauth_uid' => $fbUserProfile['id'],
    'first_name' => $fbUserProfile['first_name'],
    'last_name' => $fbUserProfile['last_name'],
    'email' => $fbUserProfile['email'],
    'gender' => $fbUserProfile['gender'],
    'locale' => $fbUserProfile['locale'],
    'picture' => $fbUserProfile['picture']['url'],
    'link' => $fbUserProfile['link']
    );
    $userData = $user->checkUser($fbUserData);

    // Put user data into session
    $_SESSION['userData'] = $userData;

    // Get logout url
    $logoutURL = $helper->getLogoutUrl($accessToken, $redirectURL.'logout.php');

    // Render facebook profile data
    if(!empty($userData)){
    $output = "<h1>APP ID ".$appId ."</h1>";
    $output .= '<h1>Facebook Profile Details </h1>';
    $output .= '<img src="'.$userData['picture'].'">';
    $output .= '<br/>Facebook ID : ' . $userData['oauth_uid'];
    $output .= '<br/>Name : ' . $userData['first_name'].' '.$userData['last_name'];
    $output .= '<br/>Email : ' . $userData['email'];
    $output .= '<br/>Gender : ' . $userData['gender'];
    $output .= '<br/>Locale : ' . $userData['locale'];
    $output .= '<br/>Logged in with : Facebook';
    $output .= '<br/><a href="'.$userData['link'].'" target="_blank">Click to Visit Facebook Page</a>';
    $output .= '<br/>Logout from <a href="'.$logoutURL.'">Facebook</a>';
    }else{
    $output = '<h3 style="color:red">Some problem occurred, please try again.</h3>';
    }

    }else{
    // Get login url
    $loginURL = $helper->getLoginUrl($redirectURL, $fbPermissions);

    // Render facebook login button
    $output = '<a href="'.htmlspecialchars($loginURL).'"><img src="images/fblogin-btn.png"></a>';
    }
    ?>
    <html>
    <head>
    <title>Login with Facebook using PHP by CodexWorld</title>
    <style type="text/css">
    h1{font-family:Arial, Helvetica, sans-serif;color:#999999;}
    </style>
    </head>
    <body>
    <!-- Display login button / Facebook profile information -->
    <div><?php echo $output; ?></div>
    </body>
    </html>




    // fbconfig.php
    // sito riferimento https://www.codexworld.com/login-wit...ook-using-php/
    error_reporting(E_ALL);
    if(!session_id()){
    session_start();
    }

    // Include the autoloader provided in the SDK
    require_once __DIR__ . '/facebook-php-sdk/autoload.php';

    // Include required libraries
    use Facebook\Facebook;
    use Facebook\Exceptions\FacebookResponseException;
    use Facebook\Exceptions\FacebookSDKException;

    /*
    * Configuration and setup Facebook SDK
    */


    $appId = '22xxxxxxxx'; //Facebook App ID
    $appSecret = '50xxxxxx'; //Facebook App Secret
    $redirectURL = 'http://xxxxx.altervista.org/fbapp0'; //Callback URL
    $fbPermissions = array('email'); //Optional permissions



    $fb = new Facebook(array(
    'app_id' => $appId,
    'app_secret' => $appSecret,
    'default_graph_version' => 'v2.2',
    ));

    // Get redirect login helper
    $helper = $fb->getRedirectLoginHelper();

    // Try to get access token
    try {
    if(isset($_SESSION['facebook_access_token'])){
    $accessToken = $_SESSION['facebook_access_token'];
    }else{
    $accessToken = $helper->getAccessToken();
    }
    } catch(FacebookResponseException $e) {
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
    } catch(FacebookSDKException $e) {
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
    }

    ?>
    [/QUOTE]

  2. #2
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,445
    Il problema non è PHP, ma le impostazioni dell'app che hai creato sul tuo profilo developer di FB, ci sono dati obbligatori da fornire, come per esempio un link alle condizioni per il trattamento dei dati personali. Non so a quale link si riferisca l'errore che hai, ma di certo non lo risolverai con PHP, specie se lo stesso codice con un'app correttamente impostata funziona.

  3. #3
    Utente di HTML.it
    Registrato dal
    Sep 2015
    Messaggi
    8
    CiaoAlhazred
    Grazie per la tua risposta, le due app sono identiche, le ho ricontrollate 200 volte , ora ci riprovo, un saluto

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.