Automating Linkedin oAuth usin Curl and PHP -


i trying automate process of authenticating linkedin login in order perform public search people on linkedin.

first try explain doing.

i using 4 files:

  • oauth.php (required)
  • linkedin.php (php linkedin library)
  • auth.php (which gets oauth token linkedin lib file)
  • callback url demo.php?params (which, after successful authenticaton, prints current user's profile , search results using params)

the authentication url https://api.linkedin.com/uas/oauth/authorize?oauth_token=$oauthtoken.

i did 2 things, neither seems work; are:

  1. i using curl automate process of going authentication url, posting fields (username, password, oauth token, csrftoken, duration, sourcealias, etc., came know firebug).

    the 2 things change here oauth token , csrftoken (by parsing content in authentication url). able both, each time page loads, , trying print response curl_exec.

  2. trying post email , password, , trying print response.

for reference here 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 initialize consumer key , secret. we'll use # out-of-band oauth_callback $linkedin = new linkedin($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url']); //$linkedin->debug = true;  # retrieve request token. set $linkedin->request_token $linkedin->getrequesttoken(); $_session['requesttoken'] = serialize($linkedin->request_token);  # request token in hand, can generate authorization url, # we'll direct user //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.'&amp;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'; 

now used authentication url , postparams curl.

in order login process through, 1 has use linkedin web page authorization step; no way can have third party app accepting credentials , making linkedin authorization link https://api.linkedin.com/uas/oauth/authorize?oauth_token=$oauthtoken


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -