CodeIgniter Twitter API(Elliot Haughin)捕获任何URL获取参数,其中包含“oauth_token”

时间:2011-09-10 15:04:24

标签: php codeigniter twitter

似乎有点奇怪。

我正在使用Elliot Haughin's Twitter library的CodeIgniter。顺便说一下,它是一个出色的API。

但是,我在config文件夹的“autoload.php”中自动加载了这个库,我注意到这个库捕获了任何有“oauth_token”URL参数的URL。

例如,当我输入

http://localhost/myapp/index.php/controller?oauth_token=1

然后它会抛出错误

A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: libraries/Tweet.php
Line Number: 205

我浏览了库,发现以下构造函数调用了一个检查GET参数的方法。

class tweetOauth extends tweetConnection {

  function __construct()
  {
    parent::__construct();
    ..
    ..
    ..
    $this->_checkLogin();
  }

并且方法“_checkLogin()”执行以下操作

private function _checkLogin()
{
  if ( isset($_GET['oauth_token']) )
  {
    $this->_setAccessKey($_GET['oauth_token']);
    $token = $this->_getAccessToken();
    $token = $token->_result;
    ...
    ...

解决此问题的最佳方法是什么?

1 个答案:

答案 0 :(得分:0)

如果您没有检查有效的oauth_token,为什么在查询字符串中有oauth_token? 我假设你想在某个时候声明已经设置了oauth_token并且你只是使用oauth_token = 1作为参数?

该库设置为始终针对oauth_token进行测试,如果您正在自动加载它,那么以任何其他方式执行它并不是一个可行的调整。你需要一个运行的控制器(也许是方法)的白名单/黑名单,这几乎无法实现自动加载。

如果真的需要使用oauth_token = 1,你可以将其改为

if ( isset($_GET['oauth_token']) && $_GET['oauth_token']!==1)

如果您为oauth_token使用了多个值(或者如果您担心可以通过将oauth_token = X附加到URL来触发错误),则可以尝试使用正则表达式,假设所有oauth_tokens都遵循模式(32个字符长等)。

或者你也可能只是退出/返回false,具体取决于$ token = $ this-> _getAccessToken()中返回的内容。取决于代码中其他地方发生的事情。看起来像返回false应该只是工作。

相关问题