当我们使用 FbConnect 从 Facebook 重定向回我的网站时,如何对我的网址进行编码或解码
自从我尝试解决这个问题以来,我已经在这里问过它,但没有得到任何答复,我一直在各种意义上搜索我的问题,但我就是做不到。 我只需要知道当我向 Facebook 发送我的网址时如何获得有效的网址我希望 Facebook 将我的用户重定向回来: site_url('main/verification')
(我正在使用 codeIgniter )
所以我的loginUrl看起来像这样:
https://www.facebook.com/dialog/oauth?client_id=248650435198175.&.redirect_uri=http%.3A%.2F%.2Flocalhost%.2FSocialCart%.2Findex.php%.3F%.2Fmain%.2Fverification&state=004dc1ebe9e081b2222408434af7dbd5&scope=email
(DELETE ALL POINTS AFTER ALL THE %)
一旦我点击链接,我就会被定向到FaceBook,但是随后,我会被重定向到我的主页(而不是主/验证)在我的浏览器中使用该 URL:
http://localhost/SocialCart/index.php?%.2.Fmain%.2.Fverification&state=0e3ae6ca3e7869f618d65ad&code=AQCwwZUevy-SfeNLgUC55Rg0bi7noi_oczwt_2TmR-DobC8xc6STYIW82VLi23fzf9d-J5tdufdOLpc#_=_
好吧,我已经删除了那段长代码的一部分,但是您会看到,在我的 index.php?
之后,我得到了一个 %.2。 F 代替 /
和 &应该是? (我认为)
(删除每个 %2 和 2F 之间的点“.”)
我该如何修复它?为什么我的redirectUrl 仅被浏览器部分解码?它似乎解码直到index.php,然后,它停止用“/”替换所有“%.2F”(在%之后再次没有意义) 我想我需要 url 重写或 urlencode() 函数,但事实是只有一半的 url 得到了很好的解释,其余的则不然。我现在真的不知道该怎么办..
我想我必须检查 getLoginUrl() 函数,它的函数负责检索将用户从 fb 重定向到我的网站的登录 url 部分(如果 url)编码良好,但我已经尝试了所有方法,但似乎没有任何效果。
这是该函数(您可以在 php API 图表的任何 base_facebook.php 中找到该函数。):
/**
* Get a Login URL for use with redirects. By default, full page redirect is
* assumed. If you are using the generated URL with a window.open() call in
* JavaScript, you can pass in display=popup as part of the $params.
*
* The parameters:
* - redirect_uri: the url to go to after a successful login
* - scope: comma separated list of requested extended perms
*
* @param array $params Provide custom parameters
* @return string The URL for the login flow
*/
public function getLoginUrl($params=array()) {
$this->establishCSRFTokenState();
$currentUrl = $this->getCurrentUrl();
// if 'scope' is passed as an array, convert to comma separated list
$scopeParams = isset($params['scope']) ? $params['scope'] : null;
if ($scopeParams && is_array($scopeParams)) {
$params['scope'] = implode(',', $scopeParams);
}
return $this->getUrl(
'www',
'dialog/oauth',
array_merge(array(
'client_id' => $this->getAppId(),
'redirect_uri' => site_url(), // possibly overwritten
'state' => $this->state),
$params));
}
谢谢
its been I while since I try to solve that problem, I've already asked it here, but didn't get any response, I've been googleling my problem in every sense but I just can't make it.
I just need to know how could I get a valid url when I send to FaceBook my url I want FaceBook to redirect my user back : site_url(‘main/verification’)
(I'm working with codeIgniter)
so my loginUrl looks like this :
https://www.facebook.com/dialog/oauth?client_id=248650435198175.&.redirect_uri=http%.3A%.2F%.2Flocalhost%.2FSocialCart%.2Findex.php%.3F%.2Fmain%.2Fverification&state=004dc1ebe9e081b2222408434af7dbd5&scope=email
(DELETE ALL POINTS AFTER ALL THE %)
once I click on the link, I’m directed to FaceBook, but then, I’m redirected to my main page (and not main/verification) with that URL in my browser :
http://localhost/SocialCart/index.php?%.2.Fmain%.2.Fverification&state=0e3ae6ca3e7869f618d65ad&code=AQCwwZUevy-SfeNLgUC55Rg0bi7noi_oczwt_2TmR-DobC8xc6STYIW82VLi23fzf9d-J5tdufdOLpc#_=_
Well I’ve deleted a part of that long code but you see that I get, after my index.php?
an %.2.F instead of an /
and the & should be ? (I think)
(remove the points ‘.’ between every %2 and 2F)
How could I fix it please ? WHY is my redirectUrl only partially decoded by my browser ? it seems to decode until the index.php and then, it stops replacing all the '%.2F' by '/' (once again no point after the %)
I guess I’m gonna need the url rewriting or urlencode() functions but the fact is that only half of the url is well interpreted, and not the rest. I really don't now what to do ..
I guess I have to check into the getLoginUrl() function, its the function which is in charge of retrieving the part of the login url that redirect the user from fb to my websiteif the url is well encoded but I've tried everything and nothing seems to work.
Here is the function (that you can find in any base_facebook.php of the php API graph.) :
/**
* Get a Login URL for use with redirects. By default, full page redirect is
* assumed. If you are using the generated URL with a window.open() call in
* JavaScript, you can pass in display=popup as part of the $params.
*
* The parameters:
* - redirect_uri: the url to go to after a successful login
* - scope: comma separated list of requested extended perms
*
* @param array $params Provide custom parameters
* @return string The URL for the login flow
*/
public function getLoginUrl($params=array()) {
$this->establishCSRFTokenState();
$currentUrl = $this->getCurrentUrl();
// if 'scope' is passed as an array, convert to comma separated list
$scopeParams = isset($params['scope']) ? $params['scope'] : null;
if ($scopeParams && is_array($scopeParams)) {
$params['scope'] = implode(',', $scopeParams);
}
return $this->getUrl(
'www',
'dialog/oauth',
array_merge(array(
'client_id' => $this->getAppId(),
'redirect_uri' => site_url(), // possibly overwritten
'state' => $this->state),
$params));
}
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要对 base_facebook.php 进行任何更改
使用以下代码:
Don't make any changes in base_facebook.php
Use following code:
您的登录网址是这样的:
重定向 uri 是
解码后的redirect_uri 网址是:
您的redirect_uri 中有一个
%3F
Your login url is this:
the redirect uri is
The url decoded redirect_uri is:
You have a
%3F
in the redirect_uri