我正在尝试自动化验证 LinkedIn 登录的过程,以便在 LinkedIn 上对人员进行公开搜索。
首先,我将尝试解释我在做什么。
我正在使用四个文件:
oAuth.php
(必需的)linkedin.php
(php LinkedIn 库)auth.php
(从 LinkedIn lib 文件中获取 oAuth 令牌)- 回调 url
demo.php?params
(在成功验证后,使用参数打印当前用户的个人资料和搜索结果)
身份验证网址是https://api.linkedin.com/uas/oauth/authorize?oauth_token=$oauthtoken
.
我做了两件事,似乎都没有用;他们是:
我正在使用 curl 自动执行访问身份验证 url、发布字段(用户名、密码、oauth 令牌、csrfToken、持续时间、sourceAlias 等,我从 Firebug 了解到)的过程。
这里唯一改变的两件事是 oauth 令牌和 csrfToken(通过解析身份验证 url 中的内容)。每次页面加载时,我都能得到两者,最后尝试从 curl_exec 打印 GET 响应。
尝试仅发布电子邮件和密码,并尝试打印 GET 响应。
供参考的是我的auth.php
:
function extract_unit($string, $start, $end)
{
$pos = stripos($string, $start);
$str = substr($string, $pos);
$str_two = substr($str, strlen($start));
$second_pos = stripos($str_two, $end);
$str_three = substr($str_two, 0, $second_pos);
$unit = trim($str_three); // remove whitespaces
return $unit;
}
session_start();
$config['base_url'] = 'http://linkedin.tweetrank.tk/auth.php';
$config['callback_url'] = 'http://linkedin.tweetrank.tk/demo.php';
$config['linkedin_access'] = 'my key';
$config['linkedin_secret'] = 'my secret';
include_once "linkedin.php";
# First step is to initialize with the 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;
# Now we retrieve a request token. It will be set as $linkedin->request_token
$linkedin->getRequestToken();
$_SESSION['requestToken'] = serialize($linkedin->request_token);
# With a request token in hand, we can generate an authorization URL, which
# we'll direct the user to
//echo "Authorization URL: " . $linkedin->generateAuthorizeUrl() . "\n\n";
echo $url = $linkedin->generateAuthorizeUrl();
$token = $linkedin->generateAuthorizeToken();
//echo '<br><br>';
$data = file_get_contents($url);
$csrfToken = extract_unit($data,'name="csrfToken" value="','"');
//echo $csrfToken;
//echo $token;
//echo 'https://www.linkedin.com/uas/oauth/authenticate?oauth_token='.$token.'&trk=uas-continue';
// INIT CURL
$postParams = 'email=myemail&password=mypassword&duration=720&authorize=Ok%2C+I%27ll+Allow+It&extra=&access=-3&agree=true&oauth_token='.$token.'&appId=&csrfToken='.$csrfToken.'&sourceAlias=0_8L1usXMS_e_-SfuxXa1idxJ207ESR8hAXKfus4aDeAk';
现在我使用了身份验证 URL 和postParams
with curl。