LinkedIn で人の公開検索を実行するために、LinkedIn ログインの認証プロセスを自動化しようとしています。
最初に、私が何をしていたかを説明しようとします。
私は4つのファイルを使用しています:
oAuth.php(必要)linkedin.php(php LinkedIn ライブラリ)auth.php(LinkedIn lib ファイルから oAuth トークンを取得します)- コールバック URL
demo.php?params(認証が成功した後、現在のユーザーのプロファイルと params を使用した検索結果を出力します)
認証 URL はhttps://api.linkedin.com/uas/oauth/authorize?oauth_token=$oauthtoken.
私は2つのことをしましたが、どちらもうまくいかないようです。彼らです:
curl を使用して、認証 URL に移動し、フィールド (ユーザー名、パスワード、oauth トークン、csrfToken、期間、sourceAlias など、Firebug から知りました) を投稿するプロセスを自動化しています。
ここで変更されるのは、oauth トークンと csrfToken の 2 つだけです (認証 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 とpostParamswith curl を使用しました。