1

PHP code

$base_url = 'https://api.linkedin.com/v1/people/~/';
$url = $base_url . 'shares';
$xml  = '<share>';
$xml .= '<comment>' . 'test'. '</comment>';
$xml .= '<content>';
$xml .= '<title>' . 'TEST' . '</title>';
$xml .= '<submitted-url>' . 'http://www.google.com' . '</submitted-url>';
$xml .= '<description>' . 'description' . '</description>';
$xml .= '</content>';
$xml .= '<visibility><code>anyone</code></visibility>';
$xml .= '</share>';

$signature = new OAuthSignatureMethod_HMAC_SHA1();
$consumer = new OAuthConsumer('my_consumer_key', 'my_consumer_secret', NULL);

How can I get a $token and $secret variable which is oauth_token and oauth_token_secret when all I get is an access token when sending an authorization request to the user? Is there a way I can get the oauth_token and oauth_token_secret using the access token?

$token = new OAuthConsumer($token, $secret, 1);
$request = OAuthRequest::from_consumer_and_token($consumer, $token, 'POST', $url, array ());
$request->sign_request($signature, $consumer, $token);
$header = $request->to_header();
$response = _linkedin_http_request($url, $header, $xml);

/*
 * Some internal helper functions...
 */
function _linkedin_http_request($url, $header, $body = NULL) {

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
    curl_setopt($ch, CURLOPT_URL, $url);

    if ($body) {
        curl_setopt($ch, CURLOPT_POST, 1);
        if ($body == 'token_request') {
            curl_setopt($ch, CURLOPT_POSTFIELDS, '');
        }
        else {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array($header, 'Content-Type: text/xml;charset=utf-8'));
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
        }
    }

    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}
3
  • please elaborate and that link is not valid ?
    – hash6
    Sep 25, 2014 at 13:28
  • You get your API key and secret here: linkedin.com/secure/developer To get the rest, check out the OAuth documentation that will describe the steps to follow: OAuth Authentication Sep 25, 2014 at 13:35
  • Same issue I am also getting , I want the users oauth_token and oauth_secret who has authorized me for the access token . please let me know
    – harshal
    Sep 25, 2014 at 13:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.