大量 API/框架混搭问题(oAuth、Facebook、Twitter、Code Igniter)
我正在处理的一个项目遇到了(很多,但目前)一个问题。
- 这是一个在 Code Igniter 上运行的 PHP 项目
- 这是一个想要使用 oAuth Twitter 授权的 Facebook 应用程序
CodeIgniter 默认情况下会清除 $_GET 数组,因为它使用 URI 来控制 MVC 内容。您可以关闭此功能以访问 GET 数组,并使用 example.com/?c=MyController&m=MyMethod
之类的字符串来解决此问题。
Facebook 要求您为您的应用程序页面定义根 URL。这对我来说意味着:
apps.facebook.com/MyApplication == http://www.myownserver.com/index.php/c=SignIn&
我以这种方式设置它,以便它可以使用 $_GET 数组。当 Twitter(我假设任何其他实现)使用 oAuth 时,它会传递回您想要的任何 URL,并在末尾附加 ?token=250937602736037609273609327
,所以我最终得到的结果
app.facebook.com/MyApplication/?token=302870637602746094276097
看起来是正确的,但实际上是实际上相当于
http://www.myownserver.com/index.php/c=SignIn&?token=302870637602746094276097
所以问题是 URL 中不能有两个问号;第二个需要是一个与号 (&) 以将更多值串在一起。错误消息是可预测的不允许的关键字符。
任何人都可以想出一个好的/聪明的方法来解决我遇到的这个问题吗?我真的不想放弃这个设置的 CodeIgniter 部分,因为它有一个很棒的数据库抽象和很好的助手,我已经在上面写了很多代码。
感谢您的任何建议。
I'm having (many, but for now,) one problem with a project I'm working on.
- It is a PHP project run on Code Igniter
- It is a Facebook app that wants to use oAuth Twitter authorization
CodeIgniter by default clears the $_GET array because it uses the URI for controlling MVC stuff. You can turn this off to access the GET array, and use a string like example.com/?c=MyController&m=MyMethod
to get around this.
Facebook asks you to define a root url for you application page. This means that for me:
apps.facebook.com/MyApplication == http://www.myownserver.com/index.php/c=SignIn&
I have it set up this way so that it can use the $_GET array. When Twitter (and I assume any other implementation) uses oAuth, it passes back to whatever URL you want with the ?token=250937602736037609273609327
appended onto the end, so I end up at
app.facebook.com/MyApplication/?token=302870637602746094276097
which looks right, but is in fact equivalent to
http://www.myownserver.com/index.php/c=SignIn&?token=302870637602746094276097
So the problem is that you can't have two question marks in the URL; the second needs to be an ampersand (&) to string more values together. The error message is a predictable Disallowed Key Characters.
Can anyone thing of a good/clever way to get around this issue I'm having? I really don't want to dump the CodeIgniter part of this setup because it has a great DB abstraction and good helpers that I've already written a good bit of code on.
Thanks for any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯。也许你可以用 mod_rewrite 和 QSA 标志做一些聪明的事情来自动将其串在一起?即重写您的“根网址”,而不是在 facebook 中将“&”符号添加到其上?
Hm. Can you do something clever with mod_rewrite and the QSA flag to automatically string it together, perhaps? I.e. have a rewrite for your 'root url' instead of tacking the ampersand onto it in facebook?
也许我不完全理解你的问题,但是你不能将
&
添加到 application/config/config.php 文件中的$config['permissed_uri_chars']
中吗?Perhaps I don't fully understand your problem, but can't you add
&
to$config['permitted_uri_chars']
in the application/config/config.php file?您可以扩展输入库以允许查询字符串和漂亮的 URL。
查看 haughin.com 的 Twitter 库,看看他是如何做到的。
You can extend the Input Library to allow query strings and pretty urls.
Check out haughin.com for the Twitter Library, and see how he did it.