【发布时间】:2015-12-02 20:56:38
【问题描述】:
我尝试进行一些简单的 LinkedIN api 调用,从授权开始。 出于测试目的,我只创建了这个我知道它有效的 $url 并打开它。
但是有一个区别,如果我通过下面的代码调用这个 URL 并输入我的链接凭据,我会自动重定向到
http://localhost/uas/oauth2/authorizedialog/submit
这看起来像是用“localhost”替换了一些linkedin URL,我确定它不是我的redirect_uri,我没有在任何地方定义它。
我找不到发生这种情况的原因,如果我在登录后直接在浏览器中打开页面(只需从 $url 复制粘贴 URL),我将被重定向到 example.com。
我的代码:
//define path
$url = "https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=MyIdHere&redirect_uri=https%3A%2F%2Fwww.example.com%2Fauth%2Flinkedin&state=DCEeFWf45A53sdfKef424&scope=r_basicprofile";
// set up the curl resource
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded'
));
// execute the request
$output = curl_exec($ch);
// output the auth information - includes the header
var_dump($output);
// close curl resource to free up system resources
curl_close($ch);
?>
感谢您的建议。
【问题讨论】: