“ redirect_uri URL必须是绝对的” Facebook PHP SDK上的错误 [英] "The redirect_uri URL must be absolute" error on Facebook PHP SDK
问题描述
编辑:在基本设置下,我将 http://www.example.com
(例如,是我的实时网站)作为网站网址 。在应用程序域下,我还有 www.example.com
和 example.com
。 / p>
我得到的错误是:
redirect_uri URL必须是绝对的
我尝试登录时代码中断。这是我的 getLoginUrl()
的代码:
<?php
$ fb =新的Facebook\Facebook([
'app_id'=>'MYAPPID',
'app_secret'=>'MYAPPSECRET',
'default_graph_version'=>'v2.5',
]);
$ redirectURI =‘http://example.com/login-callback.php’;
$ encodedRedirectURI = urlencode($ redirectURI);
$ helper = $ fb-> getRedirectLoginHelper();
$ loginUrl = $ helper-> getLoginUrl(
array(
'scope'=>'ads_management,read_insights',
'redirect_uri'=> $ encodedRedirectURI
)
);
echo’< a href =’。$ loginUrl。’>使用Facebook登录!< / a>’;
?>
为什么会发生此错误?
为什么会发生此错误?
因为您是URL -对该URL进行编码,然后再将其传递给 getLoginUrl
方法。
SDK在内部进行处理-因此现在您有一个经过两次 编码的URL,这使其无法识别为有效的绝对URL。
因此只需通过该方法的URL 不应用任何额外的编码。
编辑:此外,该方法 getLoginUrl
需要两个参数-首先是重定向URI,然后是范围,第二个是-不都作为 one
$ loginUrl = $ helper-> getLoginUrl(
$ redirectURI,
array(' ads_management','read_insights')
);
EDIT: I have http://www.example.com
(example being my live site) as the Site URL under basic settings. I also have www.example.com
and example.com
under App Domains.
The error I'm getting is:
The redirect_uri URL must be absolute
My code breaks when I try to login. Here's my code for the getLoginUrl()
:
<?php
$fb = new Facebook\Facebook([
'app_id' => 'MYAPPID',
'app_secret' => 'MYAPPSECRET',
'default_graph_version' => 'v2.5',
]);
$redirectURI = 'http://example.com/login-callback.php';
$encodedRedirectURI = urlencode($redirectURI);
$helper = $fb->getRedirectLoginHelper();
$loginUrl = $helper->getLoginUrl(
array(
'scope' => 'ads_management,read_insights',
'redirect_uri' => $encodedRedirectURI
)
);
echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
?>
Why is this error happening?
Why is this error happening?
Because you are URL-encoding the URL, before passing it to the getLoginUrl
method.
The SDK takes care of that internally - so now you have a URL that has been URL-encoded twice, and that makes it unrecognizable as a valid, absolute URL.
So just pass the URL to that method without applying any extra encoding.
Edit: Additionally, the method getLoginUrl
expects two parameters - first the redirect URI, and then the scope as the second one - not both as one array.
$loginUrl = $helper->getLoginUrl(
$redirectURI,
array('ads_management', 'read_insights')
);
这篇关于“ redirect_uri URL必须是绝对的” Facebook PHP SDK上的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!