简体   繁体   中英

Facebook OAuth, page not found

I've been trying to implement the Facebook OAuth SDK for the past couple of days but keep running into a weird broken link error.

I have followed their instructions on the facebook SDK and used this code for login.php (???? to censor app ID and secret)

$fb = new Facebook\Facebook ([
    'app_id' => '????????????????',
    'app_secret' => '????????????????',
    'default_graph_version' => 'v.2.4'
    ]);
$helper = $fb->getRedirectLoginHelper();
$loginUrl = $helper->getLoginUrl('http://url.ca/login-callback.php');

This redirects to the login-callback.php file which is what Facebook recommends. Using their provided template code for login-callback.php , mine looks like this:

<?php
session_start();
require_once 'src/Facebook/autoload.php';
//Create the Facebook service
$fb = new Facebook\Facebook ([
    'app_id' => '????????????????',
    'app_secret' => '????????????????',
    'default_graph_version' => 'v.2.4'
    ]);

$helper = $fb->getRedirectLoginHelper();
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)) {
    // Logged in!
    $_SESSION['facebook_access_token'] = (string) $accessToken;

    // Now you can redirect to another page and use the
    // access token from $_SESSION['facebook_access_token']
}
?>

But after being redirected from login.php (clicking on the a href element), I arrive at this:

Sorry, this page isn't available

The link you followed may be broken, or the page may have been removed.

On the Facebook page, no prompt to login, no nothing. I've made my app public already and added this Url to the app as well as ensuring OAuth is enabled, but nothing seems to be working. Does anyone with experience using Facebook OAuth have any idea what's going on?

Is that 'v.2.4' a typo in your question?

The string used in the API should be v2.4 - if you have an extra '.' it's linking you to a URL similar to the real URL of the login dialog, but with an invalid version number in the path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM