【发布时间】:2012-05-08 06:45:35
【问题描述】:
我已经通过我的 CodeIngiter 应用程序成功访问了 LinkedIn API。我搬到了几乎相同的服务器并实现了 i18n 库,但它停止了工作。
用户在 LinkedIn 上进行身份验证后,它会返回正确的 URL,但会生成一系列以 Undefined index: oauth_verifier 开头的错误
使用i18n library 后,我的网址现在在第一段中有两个字母语言代码,例如“en”或“br”。
编辑:这是我正在使用的Linkedin library。
我认为这会导致 $_REQUEST['oath_verifier'] 的设置出现路由问题
非常感谢您对此的任何帮助。
节选自控制器:
class LinkLogin extends MY_Controller {
function __construct(){
parent::__construct();
$this->load->helper('url');
$this->load->model('profile_model');
$this->load->model('generic_model');
include_once (APPPATH.'libraries/Linkedin.php');
}
function index(){
}
function initiate(){
session_start();
$this->load->helper('url');
$config['linkedin_access'] = "***";
$config['linkedin_secret'] = "***";
$config['base_url'] = "http://www.youinapage.com/linklogin/initiate/";
if ($this->uri->segment(4) == 'profile') {
$config['callback_url'] = "http://www.youinapage.com/linklogin/get_profile_linkedin/";
}
if ($this->uri->segment(4) == 'resume') {
$config['callback_url'] = "http://www.youinapage.com/linklogin/get_resume_linkedin/";
}
function get_resume_linkedin() {
session_start();
$this->load->library('format');
$config['linkedin_access'] = "***";
$config['linkedin_secret'] = "***";
$config['base_url'] = "http://www.youinapage.com/linklogin/initiate/";
$config['callback_url'] = "http://www.youinapage.com/linklogin/get_resume_linkedin/";
# First step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback
$linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url'] );
//$linkedin->debug = true;
# First step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback
$linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url'] );
//$linkedin->debug = true;
if (isset($_REQUEST['oauth_verifier'])){
$_SESSION['oauth_verifier'] = $_REQUEST['oauth_verifier'];
$linkedin->request_token = unserialize($_SESSION['requestToken']);
$linkedin->oauth_verifier = $_SESSION['oauth_verifier'];
$linkedin->getAccessToken($_REQUEST['oauth_verifier']);
$_SESSION['oauth_access_token'] = serialize($linkedin->access_token);
header("Location: " . $config['callback_url']);
exit;
}
else{
$linkedin->request_token = unserialize($_SESSION['requestToken']);
$linkedin->oauth_verifier = $_SESSION['oauth_verifier']; // ERROR: Undefined index: oauth_verifier
$linkedin->access_token = unserialize($_SESSION['oauth_access_token']);
}
【问题讨论】:
-
好吧,从表面上看,这是因为会话中没有设置
oath_verifier,如果您在没有设置$_REQUEST['oath_verifier']的情况下依次执行两个请求,就会发生这种情况。或者直接去控制器而不请求oath_verifier。你为什么要检查它是否在$_REQUEST中?我从来不需要在 codeigniter 中这样做。 -
这段摘录实际上来自哪里?在方法内还是在构造函数内?
-
知道了。摘录来自我创建的 CodeIgniter 中的控制器,该控制器处理与我正在使用的 LinkedIn 库的所有交互(不是我的)。如果我发布其他内容会有帮助吗?这段代码之前都可以工作——我几乎可以肯定 i18n 库正在影响 URL 的解释方式,从而导致了问题,只是看不到这对会话有何影响。
-
oath_verifier应该通过 post 或 get-requests 设置吗?我真的不知道它会如何设置,所以我不知道它将如何选择走哪条路。看看这是如何决定的会很有帮助。知道该摘录是来自控制器的方法还是来自控制器的构造函数仍然很有用。或者告诉我们您摘录的函数的名称以及您的类/控制器的名称。 -
当然。我已经添加了几乎所有的控制器和我正在使用的库的链接。那应该显示一切。非常感谢您的帮助!
标签: php codeigniter oauth linkedin