Facebook 错误“验证验证码时出错”
非常奇怪的错误。我使用 gide http://developers.facebook.com/docs/authentication/。所以我创建了对fb的请求并传递redirect_uri。我在本地主机上使用测试站点。所以如果我通过了
redirect_uri=http://localhost/test_blog/index.php
它工作正常,但如果我通过
redirect_uri=http://localhost/test_blog/index.php?r=site/ oauth2
它不想工作。我尝试使用
redirect_uri= . urlencode('http://localhost/test_blog/index.php?r=site/oauth2< /a>)
但不起作用。 我试着解释一下。我成功获取代码,但是当我访问 https://graph.facebook.com/me?access_token 我收到错误“验证验证码时出错”。我检查了evering,错误位于 ?r=site/oauth2 但我需要传递一些参数 有人可以帮助我吗? 我读了帖子 http://forum.developers.facebook.net/viewtopic.php? id=70855 但对我来说没有任何作用
very strange error. i use gide http://developers.facebook.com/docs/authentication/. so i create request to fb and pass redirect_uri. i use test site on localhost. so if i pass
redirect_uri=http://localhost/test_blog/index.php
it works fine, but if i pass
redirect_uri=http://localhost/test_blog/index.php?r=site/oauth2
it don't want work. i try to use
redirect_uri= .
urlencode('http://localhost/test_blog/index.php?r=site/oauth2)
but not work.
i try to explaine. i success get code, but when i access https://graph.facebook.com/me?access_token i get error 'Error validating verification code'. i checked evering, error is in ?r=site/oauth2 but i need passing some params
can somebody help me?
i read post http://forum.developers.facebook.net/viewtopic.php?id=70855 but nothing work for me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
目前(截至 2011 年 3 月)存在关于如何构成有效的 redirect_uri 的未记录的要求。
首先,授权的redirect_uri参数和access_token必须匹配。
显然 Facebook(或者更确切地说 OAuth2)正在使用 redirect_uri 作为内部密钥来编码为 access_token 请求返回的代码。这有点聪明,因为它会验证回您的网站。它解释了为什么原本不需要redirect_uri 参数的access_token 请求需要一个。
其次,您不能在redirect_uri 中使用许多特殊字符。
关于是否可以传递参数存在很多争论。他们可以,你限制哪些字符是有效的,但没有人发布我知道的列表。传统方法(如 url/html 编码)将失败,因为百分比(%) 无效。斜杠 (/) 也无效,因此嵌套重定向 url 将始终失败。克服特殊字符限制的唯一方法是将参数值编码为 base64。如果您使用的是 ASP.NET,请查找 Convert.ToBase64。
最后,这更多的是一个旁注。有很多程序员传递错误信息,认为一个简单的解决方案是传递 type=client_cred。这可能会限制您对授权中请求的某些权限的访问。这是不可取的。
There are presently (as of March 2011) undocumented requirements regarding what makes a valid redirect_uri.
First, both redirect_uri paramaters to authorize and access_token must match.
Apparently Facebook (or rather OAuth2) is using the redirect_uri as a internal key to encode the code returned for the access_token request. It's kinda clever since it verifies back to your site. It explains why the access_token request which wouldn't otherwise need a redirect_uri parameter requires one.
Second, you cannot use many special characters in the redirect_uri.
A lot of discussion rages whether parameters can be passed at all. They can, you're limited which characters are valid but no one has published a list that I know. Traditional methods like url/html encoding will fail because percent(%) is not valid. Slash (/) is not valid either so a nested redirection url will always fail. The ONLY way to overcome the special char limitation is to encode the value of the parameter to base64. If you're using ASP.NET, look up Convert.ToBase64.
Lastly, and this is more of a side-note. There are a lot of programmers passing along misinformation that a simple solution is to pass type=client_cred. This may limit your access to some of the permissions you requested in your authorization. It is inadvisable.
使用
redirect_uri=http://localhost:8000
(编码为http%3A%2F%2Flocalhost%3A8000
)测试时整天遇到同样的问题...解决方案是只是为了确保将尾部斜杠
/
放在 uri 的末尾。所以redirect_uri=http://localhost:8000/
(编码为http%3A%2F%2Flocalhost%3A8000%2F
)。再次确保两个请求的
redirect_uri
相同。Had the same problem all day when testing with
redirect_uri=http://localhost:8000
(encoded tohttp%3A%2F%2Flocalhost%3A8000
)...Solution was simply to make sure to put the trailing slash
/
on the end of the uri. Soredirect_uri=http://localhost:8000/
(encoded tohttp%3A%2F%2Flocalhost%3A8000%2F
).Again, make sure the
redirect_uri
is identical for both requests.我遇到过这个问题。我知道我的 URL 是相同的,因为我使用了具有相同 $var 的类,但我不断收到 400 响应以及 JSON 响应中的错误。
我做的唯一一件事就是将我的redirect_uri从:更改
为
Yeh,只需添加尾部斜杠即可。
I have had this problem. I knew for a fact that my URLs were the same because I used a class with the same $var, but I kept getting the 400 response and that error in the JSON response.
The only thing I did was change my redirect_uri from:
to
Yeh, just added the trailing slash and it worked.
您实际上不需要编码,只需将“/”放在您的redirect_url 末尾,一切都应该没问题!
You don't really need to encode, just put the '/' at the end of your redirect_url and everything should be fine!
Aaron Wheeler 提供的部分信息不正确。
确实,两个请求中的“redirect_uri”参数必须相同,但是完全可以对常规 URL 进行 URL 编码并将其用作“redirect_url”参数的值,只要您要小心地进一步对任何内联 URL 进行 URL 编码。
例如,您希望 facebook 重定向到以下 URL:
尝试将用户重定向到
Will 会失败,因为
/Party/Pants
创建无效 URL但是,重定向到
Will 会按预期工作。
如果您在第二个验证应用程序请求中使用返回的 redect_uri 值,请务必再次进行 url 编码 - 在填充 $_GET 超级全局时,该值会自动进行 URL 解码。 - 这就是让我绊倒的原因。
PS 在您的实际代码中,我建议使用 sprintf() 而不是像我的示例中那样将字符串链接在一起,以获得更好的可读性。
Part of the information given by Aaron Wheeler is incorrect.
It is true that the 'redirect_uri' parameter must be identical in both requests, however it is perfectly possible to URL encode a regular URL and use that as the value for the 'redirect_url' parameter, so long as you're careful to further URL encode any inline URLs.
For instance, you wish facebook to redirect to the following URL:
Attempting to redirect the user to
Will fail as
/Party/Pants
creates an invalid URLHowever, redirecting to
Will work as expected.
If you are using the returned the redrect_uri value in the second, authenticate application request, be sure to url encode again - the value is automatically URL decoded when populating the $_GET superglobal. - This is what tripped me up.
P.s. In your actual code, I'd recommend using sprintf() rather than chaining string together like in my example, for better readability.
据我所知,这里的问题是redirect_uri必须以“/”结尾并且不包含“?”或其他特殊字符。我认为这就是您收到“验证验证码时出错”的原因。仅当您使用 file_get_contents() 时才会出现此错误,而在使用 facebook php 库时不会出现此错误。
这是php的解决方案,不知道其他SDK是否也会出现这个错误。
From what I can see, the problem here is that the redirect_uri must end with '/' and not contain '?' or other special characters. I think that is why you are getting 'Error validating verification code'. This error only appears if you are using file_get_contents(), and not when using the facebook php library.
This is the solution for php, don't know if this error appears in other SDK's.
我不确定它是否有帮助,但我建议仅对网址中的值进行编码。不是全部。例如:
I'm not sure if it will help, but i would suggest to encode only values in the url. Not the whole thing. eg:
我正在使用 pb,最后修复它,在 url 中添加 type=client_cred 参数。
I was having the pb and finally fix it adding the type=client_cred parameter in the url.
为此苦苦挣扎了一段时间。由于我不需要重定向,但需要重定向参数,所以我的解决方案是简单地将其设置为空 -
Struggled with this for a while. Since I didn't want a redirect, but the redirect parameter is required, my solution was to simply set it to nothing -
我刚刚遇到了同样的问题。
诚然,我是一个超级n00b,所以如果这个解决方案在实际实践中没有任何意义,请原谅。
我只需使用 FB Connect 按钮在页面中设置一个带有测试变量的短熔丝 cookie(1-2 分钟)。当 FB 返回给我的数据解析/处理脚本的信息时,我检查了我正在重定向它的 cookie,如果找到,则使用 header:location 将用户定向到正确的 URL。
当然,有些浏览器/用户等会禁用 cookie。这显然在那里不起作用(也许使用会话变量并在 fb 数据处理程序中销毁它?)我确信有更好的方法可以做到这一点,但目前,这个创可贴可以工作。
I just had the same problem.
Admittedly, I am a super n00b so excuse me if this solution doesnt make any sense in actual practice.
I simply set a short fuse cookie (1-2 min) with a test variable in the page with my FB Connect button. When FB came back with information to my data parsing/handling script I checked for this cookie where I was redirecting it and if found, directed the user to the proper URL using header:location.
Of course some browsers/users etc disable cookies. This obviously wont work there (maybe use a session var and destroy it in the fb data handler?) I am sure there is a better way to do it but at the moment, this bandaid works.
我的答案是这样的:
在找到这个解决方案之前,我已经绞尽脑汁很久了,似乎我不是唯一一个遇到这个问题的人,我希望这对你有用!
The answer for me was this:
I've been cracking my head a long time before I found this solution, seeming I am not the only one with this issue I hope this works for you to!
我注意到你正在使用 Yii,我也在使用它,并且半天也遇到了同样的问题。如前所述,问题出在您的 URL 中的特殊字符
ie r=site/oath2
您可以通过在配置中启用漂亮 URL 来修复此问题,以便您的 URL 变为
index.php/site/ oath2
不过,它似乎可以在没有尾部斜杠的情况下工作。
I noticed you are using Yii which I'm using as well and had the same problem for half the day. As mentioned, the problem is the special characters in your URL
i.e. r=site/oath2
You can fix it by enabling pretty URLS in your config so that your URL becomes
index.php/site/oath2
It seems to work without the trailing slash though.