简体   繁体   English

Facebook OAuth,找不到页面

[英]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. 在过去的几天里,我一直在尝试实施Facebook OAuth SDK,但一直遇到一个奇怪的断链错误。

I have followed their instructions on the facebook SDK and used this code for login.php (???? to censor app ID and secret) 我已按照facebook SDK上的说明操作,并将此代码用于login.php (????来审查应用程序ID和秘密)

$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. 这会重定向到login-callback.php文件,这是Facebook推荐的。 Using their provided template code for login-callback.php , mine looks like this: 使用他们提供的login-callback.php模板代码,我看起来像这样:

<?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: 但是从login.php (点击一个href元素)重定向后,我到达了这个:

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. 在Facebook页面上,没有提示登录,没有任何内容。 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. 我已经公开了我的应用,并将此Url添加到应用中,并确保启用了OAuth,但似乎没有任何效果。 Does anyone with experience using Facebook OAuth have any idea what's going on? 有经验使用Facebook OAuth的人是否知道发生了什么?

Is that 'v.2.4' a typo in your question? 你的问题是'v.2.4'是一个错字吗?

The string used in the API should be v2.4 - if you have an extra '.' API中使用的字符串应为v2.4 - 如果您有额外的'。' 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 它会将您链接到类似于登录对话框的真实URL的URL,但路径中的版本号无效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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