Cannot GET any information but have authenticated

26 posts / 0 new
Last post
Paul Davey FBCS CITP's picture
Joined: 08/01/2011
Wed, 01/04/2012 - 01:50
Cannot GET any information but have authenticated

Hello All,

I have the following vb.net code (see attached txt file) that appears to be working fine in the sense that I get my token and secret back successfully. However, when I try to get the default user profile information back (/people/~) I get an error. I have been looking at this for 2 days now and am not getting anywhere. All and any advice appreciated.

Some facts:
- I am using the latest Hammock Library from github.
- I get the redirection to LinkedIn for authorisation fine and can enter a pin code
- I can get an access token back
- I am happy to recieve help in either vb or c#
- I am making a desktop application, NOT a web application.

Once the code executes the following line I recieve the error:
-- Dim newresponse As RestResponse = mynewClient.Request(newrequest)

I get this response back.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
<status>404</status>
<timestamp>1325670427012</timestamp>
<request-id>ZICRKYB5OJ</request-id>
<error-code>0</error-code>
<message>Could not find person based on: ~</message>
</error>

Attached_file: 
Paul Davey FBCS CITP's picture
Joined: 08/01/2011
Wed, 01/04/2012 - 02:21

Just as an update, if I amend the last section of my code as follows:

Try
Dim mynewClient As New RestClient()
With mynewClient
.Authority = "https://api.linkedin.com/people/" '"https://api.linkedin.com"
.Credentials = mynewcredentials
.Method = Web.WebMethod.Get
.VersionPath = "1.0"
End With

Dim newrequest As RestRequest = New RestRequest
newrequest.Path = "~"
newrequest.Credentials = mycredentials
Dim newresponse As RestResponse = mynewClient.Request(newrequest)
MsgBox("!")
Catch ex As Exception
MsgBox("!")
End Try

I recieve a different message:

LinkedIn: Upgrade your Security
LinkedIn is committed to the security of our member’s data.

We use SSL encryption on all of our pages. Unfortunately, your browser does not support the level of encryption we use here at LinkedIn.

We ask that you upgrade your browser’s encryption level. This usually involves a download from your browser’s manufacturer.

Follow these links to upgrade your security:

Download Firefox
Internet Explorer High Encryption Pack
Upgrding your browser’s encryption will improve data security not only for LinkedIn, but for all other websites using SSL as well.

We apologize for the inconvenience.

— The LinkedIn Team

Kirsten Jones's picture
Joined: 06/30/2011
Wed, 01/04/2012 - 07:52

I'm guessing that VB is encrypting the ~ incorrectly. Can you use fiddler to watch the traffic and see what the actual request/response look like? See Debugging API Calls for more information on debugging what's going on.

Paul Davey FBCS CITP's picture
Joined: 08/01/2011
Wed, 01/04/2012 - 08:03

Not 100% sure of what is helpful here or not, but this is the output from Fiddler. Please let me know if something else is needed?

Request Here section:
GET /people/v1/~ HTTP/1.1
Authorization: OAuth oauth_callback="oob",oauth_consumer_key="MYKEY",oauth_nonce="563z9mze4t4mrew0",oauth_signature="t40Wl92sOyUI8hswASIzxyfLR6U%3D",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1325692457",oauth_token="MYTOKEN",oauth_verifier="95268",oauth_version="1.0"

Under Inspectors\Auth:
No Proxy-Authorization Header is present.

Authorization Header is present: OAuth oauth_callback="oob",oauth_consumer_key="MYKEY",oauth_nonce="563z9mze4t4mrew0",oauth_signature="t40Wl92sOyUI8hswASIzxyfLR6U%3D",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1325692457",oauth_token="MYTOKEN",oauth_verifier="95268",oauth_version="1.0"

Response Textview is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>LinkedIn: Upgrade your Security</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="/css/style.css">
</head>

<body class="errorpg">

<div id="header">
<a href="/home"><img src="/img/logos/logo.gif" width="129" height="36" alt="Linkedin"></a>
</div>

<div id="main">
<h1>LinkedIn: Upgrade your Security</h1>
<p>LinkedIn is committed to the security of our member&#8217;s data.</p>
<p>We use <abbr title="Secure Sockets Layer">SSL</abbr> encryption on all of our pages. Unfortunately, your browser does not support the level of encryption we use here at LinkedIn.</p>
<p>We ask that you upgrade your browser&#8217;s encryption level. This usually involves a download from your browser&#8217;s manufacturer.</p>
<p>Follow these links to upgrade your security:</p>
<ul>
<li><a href="http://www.getfirefox.com">Download Firefox</a></li>
<li><a href="http://www.microsoft.com/windows/ie/downloads/recommended/128bit/default.asp">Internet Explorer High Encryption Pack</a></li>
</ul>
<p>Upgrding your browser&#8217;s encryption will improve data security not only for LinkedIn, but for all other websites using <abbr title="Secure Sockets Layer">SSL</abbr> as well.</p>
<p>We apologize for the inconvenience.</p>
<p>&#8212; The LinkedIn Team</p>
</div>

</body>
</html>

Kirsten Jones's picture
Joined: 06/30/2011
Wed, 01/04/2012 - 08:05

in this case, it looks like your VB library isn't supporting https for the request. You can try making the request over http instead so we can get back to the original error :-)

Paul Davey FBCS CITP's picture
Joined: 08/01/2011
Wed, 01/04/2012 - 08:15

I have put back to http but get the same error.

To make this easier (I hope) I have uploaded my project, it just needs a set of consumer key and secret entered to make it run. All the code is in the form load event and the hammock dll is included with the project.

It can be downloaded from the following location: http://dl.dropbox.com/u/12231713/SimpleClient.zip

Thanks so much for your help so far!

Paul

Kirsten Jones's picture
Joined: 06/30/2011
Wed, 01/04/2012 - 08:54

Alas, I'm not a Windows developer, so we need to figure this out from your side (I have done some C# programming but it's a lot of overhead to get the system set up).

You're still getting the SSL error when you use http? Or are you back to the ~ error? If the latter, please post all request headers, the URL being called (per Fiddler), the response and response body.

Paul Davey FBCS CITP's picture
Joined: 08/01/2011
Wed, 01/04/2012 - 09:22

Back to the ~ error..

result 404
protocol http
Host api.linkedin.com
URL /v1/people/~

Request Headers
GET /v1/people/~ HTTP/1.1

Header Info: Authorization
OAuth oauth_consumer_key="MYKEY",oauth_nonce="nj4m2dpdlsewkj47",oauth_signature="Mm7%2FzVKkuNHw9v61Q1OMWMYt9As%3D",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1325697493",oauth_token="MYTOKEN",oauth_verifier="70561",oauth_version="1.0"

Host: api.linkedin.com

Response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
<status>404</status>
<timestamp>1325697498313</timestamp>
<request-id>IUUP12PXWW</request-id>
<error-code>0</error-code>
<message>Could not find person based on: ~</message>
</error>

Auth Response
No Proxy-Authenticate Header is present.
No WWW-Authenticate Header is present.

Raw Response
HTTP/1.1 404 Not Found
Server: Apache-Coyote/1.1
Date: Wed, 04 Jan 2012 17:18:17 GMT
Vary: *
x-li-format: xml
Content-Type: text/xml;charset=UTF-8
Content-Length: 257

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
<status>404</status>
<timestamp>1325697498313</timestamp>
<request-id>IUUP12PXWW</request-id>
<error-code>0</error-code>
<message>Could not find person based on: ~</message>
</error>

Again, thanks for the help so far!

Paul

Kirsten Jones's picture
Joined: 06/30/2011
Wed, 01/04/2012 - 10:08

You don't want to be sending the verifier to this request. You should have gotten a permanent access token from the token process, after which time the verifier isn't needed (but the permanent oauth token and secret are needed - not the ones from the original request token request, the ones you got from the access token request). It sounds like you may not have gone all the way through to getting the access token and the server doesn't know what user to perform the request for. Is that possible?

Paul Davey FBCS CITP's picture
Joined: 08/01/2011
Wed, 01/04/2012 - 10:34

I amended the code so that once I have the access token I send the following information only when requesting the people/~ information

Token
Token Secret
Type (set to oAuthtype.AccessToken)
Consumer Key
Consumer Secret
Signature Method (set to HmacSha1)
parameter handling (set to HTTPauthorizationHeader)
version (set to 1.0)

I get the same result as below:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
<status>404</status>
<timestamp>1325701930816</timestamp>
<request-id>07W9WYQ2WO</request-id>
<error-code>0</error-code>
<message>Could not find person based on: ~</message>
</error>

If I look at the InnerException in visual studio I get the following error:
The remote server returned an error: (404) Not Found.

Kirsten Jones's picture
Joined: 06/30/2011
Wed, 01/04/2012 - 10:41

Can you try the request using the OAuth test console and compare the requests? Or you can make the same query in the REST Console. Watch the traffic using fiddler and see what's different between your request and a successful request.

Paul Davey FBCS CITP's picture
Joined: 08/01/2011
Thu, 01/05/2012 - 03:28

I have used the REST Console and entered my details in to there. I have uploaded some screenshots (personal information removed) at the following link.

http://dl.dropbox.com/u/12231713/oAuthConsoleOutput.pdf

As can be seen, I recieve the same error when I used the REST console.

Kirsten Jones's picture
Joined: 06/30/2011
Thu, 01/05/2012 - 07:09

You went through the oauth authentication process (by clicking the lock to log in)?

Paul Davey FBCS CITP's picture
Joined: 08/01/2011
Thu, 01/05/2012 - 07:12

yes

Paul Davey FBCS CITP's picture
Joined: 08/01/2011
Thu, 01/05/2012 - 07:12

I am happy to provide my api keys to you for testing if that helps?

Kirsten Jones's picture
Joined: 06/30/2011
Thu, 01/05/2012 - 07:18

Just the application name. I can get the keys from that.

Paul Davey FBCS CITP's picture
Joined: 08/01/2011
Thu, 01/05/2012 - 07:20

Keys are being used from the registered application called Manager associated to my Profile.

Many thanks

Paul

Kirsten Jones's picture
Joined: 06/30/2011
Thu, 01/05/2012 - 09:43

Paul,

The REST Console does not use your keys.

Please do the following steps:
1) Go to the REST Console
2) Click the lock and select "OAuth" (not 2-legged OAuth)
3) Authenticate as the user
4) Select 1. Profile
5) Click on people/~
6) Click "GET"

Let me know if this sequence doesn't work for you.

Paul Davey FBCS CITP's picture
Joined: 08/01/2011
Thu, 01/05/2012 - 11:32

Tried as per above and it works fine.

HTTP/1.1 200 OK
x-li-format:xmlVary:*Date:Thu, 05 Jan 2012 19:31:37 GMTContent-Length:396Content-Type:text/xml;charset=UTF-8Connection:closeServer:Apache-Coyote/1.1
<?xml version="1.0" encoding="UTF-8"?>
<person>
<first-name>Paul</first-name>
<last-name>Davey FBCS CITP</last-name>
<headline>CTO, Xtravirt</headline>
<site-standard-profile-request>
<url>http://www.linkedin.com/profile?viewProfile=&key=8715396&authToken=2Iye&authType=name&trk=api*a108281*s116823*</url>
</site-standard-profile-request>
</person>

Kirsten Jones's picture
Joined: 06/30/2011
Thu, 01/05/2012 - 15:04

From there, you can look at the request headers and information, and try to figure out what's different between your request and that request.

Joined: 12/14/2011
Tue, 02/21/2012 - 05:11

I have gotten a permanent access token from the token process, but after 30 minutes it will give the error like this.please give me help it's urgent.
Array ( [linkedin] => 401 1329821129627 09KGPZCRR5 0 [unauthorized]. The token used in the OAuth request is not valid. ebc9900d-9e78-426b-9353-cd96696e2652 [info] => Array ( [url] => https://api.linkedin.com/v1/people/~/shares [content_type] => text/xml;charset=UTF-8 [http_code] => 401 [header_size] => 208 [request_size] => 787 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.276232 [namelookup_time] => 0.016223 [connect_time] => 0.072096 [pretransfer_time] => 0.201044 [size_upload] => 326 [size_download] => 326 [speed_download] => 1180 [speed_upload] => 1180 [download_content_length] => 326 [upload_content_length] => 326 [starttransfer_time] => 0.276174 [redirect_time] => 0 [certinfo] => Array ( ) [redirect_url] => ) [oauth] => Array ( [header] => Authorization: OAuth realm="http%3A%2F%2Fapi.linkedin.com",oauth_version="1.0",oauth_nonce="8335e2ea5db79207f5644b05ef5ef722",oauth_timestamp="1329821129",oauth_consumer_key="MYKEY",oauth_token="ebc9900d-9e78-426b-9353-cd96696e2652",oauth_signature_method="HMAC-SHA1",oauth_signature="1DrkENf6tMqC%2Foet0VduclZYayM%3D" [string] => POST&https%3A%2F%2Fapi.linkedin.com%2Fv1%2Fpeople%2F~%2Fshares&oauth_consumer_key%3Duuq488qxkz0m%26oauth_nonce%3D8335e2ea5db79207f5644b05ef5ef722%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1329821129%26oauth_token%3Debc9900d-9e78-426b-9353-cd96696e2652%26oauth_version%3D1.0 ) [success] => [error] => HTTP response from LinkedIn end-point was not code 201 )

Jeremy Johnstone's picture
Developer Advocate
Joined: 04/17/2011
Tue, 02/21/2012 - 20:41

Hi Salim,

Are you using the Javascript or the REST APIs?

-Jeremy

Joined: 12/14/2011
Tue, 02/21/2012 - 22:14

i am using REST APIs.

Kirsten Jones's picture
Joined: 06/30/2011
Wed, 02/22/2012 - 08:50

Are you using the PHP library? If so, please include the code you're using. The information you provided isn't enough to determine what the issue is. Are you able to make GET calls successfully? Does everything fail, or just write operations? You need to be very specific about what you're doing, what works, and what doesn't work.

Please read Debugging API Calls for some strategies you can try.

Joined: 12/14/2011
Wed, 02/22/2012 - 20:26

This code for when user login in linkedin in.

require_once('linkedin_3.2.0.class.php');
require_once('config.php');

// start the session
if(!session_start()) {
throw new LinkedInException('This script requires session support, which appears to be disabled according to session_start().');
}

// display constants
$API_CONFIG = array('appKey' => KEY,'appSecret' => SECRET_KEY,'callbackUrl' => NULL );
// print_r($API_CONFIG);
define('CONNECTION_COUNT', 20);
define('PORT_HTTP', '80');
define('PORT_HTTP_SSL', '443');
define('UPDATE_COUNT', 10);

// set index
$_REQUEST[LINKEDIN::_GET_TYPE] = (isset($_REQUEST[LINKEDIN::_GET_TYPE])) ? $_REQUEST[LINKEDIN::_GET_TYPE] : '';
switch($_REQUEST[LINKEDIN::_GET_TYPE])
{
default:

// * Handle user initiated LinkedIn connection, create the LinkedIn object.
//

// check for the correct http protocol (i.e. is this script being served via http or https)
if($_SERVER['HTTPS'] == 'on')
{
$protocol = 'https';
}
else
{
$protocol = 'http';
}

// set the callback url
$API_CONFIG['callbackUrl'] = $protocol . '://' . $_SERVER['SERVER_NAME'] . ((($_SERVER['SERVER_PORT'] != PORT_HTTP) || ($_SERVER['SERVER_PORT'] != PORT_HTTP_SSL)) ? ':' . $_SERVER['SERVER_PORT'] : '') . $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1';
$OBJ_linkedin = new LinkedIn($API_CONFIG);

// check for response from LinkedIn
$_GET[LINKEDIN::_GET_RESPONSE] = (isset($_GET[LINKEDIN::_GET_RESPONSE])) ? $_GET[LINKEDIN::_GET_RESPONSE] : '';
if(!$_GET[LINKEDIN::_GET_RESPONSE])
{
// LinkedIn hasn't sent us a response, the user is initiating the connection

// send a request for a LinkedIn access token
$response = $OBJ_linkedin->retrieveTokenRequest();
if($response['success'] === TRUE)
{
// store the request token
$_SESSION['oauth']['linkedin']['request'] = $response['linkedin'];
$_SESSION['companyid']=$_REQUEST['cid'];
$_SESSION['companysymbol']=$_REQUEST['s'];
$_SESSION['pagepath']=$_REQUEST['page'];

header('Location: '.LINKEDIN::_URL_AUTH.$response['linkedin']['oauth_token']);

}
else
{
// bad token request
echo "Request token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
}
}
else
{

$response = $OBJ_linkedin->retrieveTokenAccess($_SESSION['oauth']['linkedin']['request']['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']);

if($response['success'] === TRUE)
{
//print_r($response);
// the request went through without an error, gather user's 'access' tokens
$_SESSION['oauth']['linkedin']['access'] = $response['linkedin'];

// set the user as authorized for future quick reference
$_SESSION['oauth']['linkedin']['authorized'] = TRUE;

$access_token_key = $_SESSION['oauth']['linkedin']['access']['oauth_token'];
$access_token_secret_key = $_SESSION['oauth']['linkedin']['access']['oauth_token_secret'];

$qry_access_keys="select Lnk_Token_Key from eqadmin_equities_cms.company where eqadmin_equities_cms.company.Lnk_Token_Key=".$token->oauth_token."";

$result=select($qry_access_keys);
if(count($result) == 0 )
{
//echo "if condition"." ".$_SESSION['companyid'];
if(isset($_SESSION['companyid']) && $_SESSION['companyid'] != '')
{
$qry_insert="update eqadmin_equities_cms.company set eqadmin_equities_cms.company.Lnk_Token_Key='".$access_token_key."',eqadmin_equities_cms.company.Lnk_Token_Secret='".$access_token_secret_key."' where eqadmin_equities_cms.company.CompanyId=".$_SESSION['companyid']."";
}
else if(isset($_SESSION['companysymbol']) && $_SESSION['companysymbol'])
{
$qry_insert="update eqadmin_equities_cms.company set eqadmin_equities_cms.company.Lnk_Token_Key='".$access_token_key."',eqadmin_equities_cms.company.Lnk_Token_Secret='".$access_token_secret_key."' where eqadmin_equities_cms.company.Symbol='".$_SESSION['companysymbol']."'";
}
$result=other($qry_insert);

$response = $OBJ_linkedin->revoke();
if($response['success'] === TRUE)
{
//echo "response";
// revocation successful, clear session
session_unset($_SESSION['oauth']['linkedin']['request']['oauth_token'],$_SESSION['oauth']['linkedin']['request']['oauth_token_secret'],$_GET['oauth_verifier']);

}
}
echo "<script>javascript:close();</script>";

}
else
{
// bad token access
echo "Access token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
}
}
}

=================================END THE LOGIN PROCESS===================================

This code for post message.

require($_SERVER['DOCUMENT_ROOT'].'/IssuerProfile/TheoraTech.UI/TheoraTech.Client.UI/Tools/LinkedIn/linkedin_3.2.0.class.php');
require($_SERVER['DOCUMENT_ROOT'].'/IssuerProfile/TheoraTech.UI/TheoraTech.Client.UI/Tools/LinkedIn/config.php');
$token=array();
$API_CONFIG = array('appKey' => KEY,'appSecret' => SECRET_KEY,'callbackUrl' => CALLBACK_URL);
define('CONNECTION_COUNT', 20);
define('PORT_HTTP', '80');
define('PORT_HTTP_SSL', '443');
define('UPDATE_COUNT', 10);
// check the session

$OBJ_linkedin = new LinkedIn($API_CONFIG);

$token['oauth_token']=$lnkkey;
$token['oauth_token_secret']=$lnksecret;

$OBJ_linkedin->setTokenAccess($token);

// prepare content for sharing
$description=$Msg;
$msg=substr(trim($description),0,250);
$content = array();
if(!empty($description))
{
$content['comment'] = $description;
}
$response = $OBJ_linkedin->share('new', $content, 'TRUE');

================================== END FOR POST MESSAGE ======================================

i am using the PHP library. When user are login in linkedin with api i can store token_key and token_secret in database. after user is post the message from my application to linkedin. after 15-20 minutes it's working fine but after it give me error like this.

Array ( [linkedin] => 401 1329821129627 09KGPZCRR5 0 [unauthorized]. The token used in the OAuth request is not valid. ebc9900d-9e78-426b-9353-cd96696e2652 [info] => Array ( [url] => https://api.linkedin.com/v1/people/~/shares [content_type] => text/xml;charset=UTF-8 [http_code] => 401 [header_size] => 208 [request_size] => 787 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.276232 [namelookup_time] => 0.016223 [connect_time] => 0.072096 [pretransfer_time] => 0.201044 [size_upload] => 326 [size_download] => 326 [speed_download] => 1180 [speed_upload] => 1180 [download_content_length] => 326 [upload_content_length] => 326 [starttransfer_time] => 0.276174 [redirect_time] => 0 [certinfo] => Array ( ) [redirect_url] => ) [oauth] => Array ( [header] => Authorization: OAuth realm="http%3A%2F%2Fapi.linkedin.com",oauth_version="1.0",oauth_nonce="8335e2ea5db79207f5644b05ef5ef722",oauth_timestamp="1329821129",oauth_consumer_key="MYKEY",oauth_token="ebc9900d-9e78-426b-9353-cd96696e2652",oauth_signature_method="HMAC-SHA1",oauth_signature="1DrkENf6tMqC%2Foet0VduclZYayM%3D" [string] => POST&https%3A%2F%2Fapi.linkedin.com%2Fv1%2Fpeople%2F~%2Fshares&oauth_consumer_key%3Duuq488qxkz0m%26oauth_nonce%3D8335e2ea5db79207f5644b05ef5ef722%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1329821129%26oauth_token%3Debc9900d-9e78-426b-9353-cd96696e2652%26oauth_version%3D1.0 ) [success] => [error] => HTTP response from LinkedIn end-point was not code 201 )

Jeremy Johnstone's picture
Developer Advocate
Joined: 04/17/2011
Tue, 02/28/2012 - 19:01

Hi Salim,

I would recommend using the PHP code samples from our quick start guide available here:

https://developer.linkedin.com/documents/quick-start-guide

They've been vetted by us and are known to work. While that library is one of the better ones out there, anything from a 3rd party we can't fully support and insure the issue isn't in the library and not with your code.

-Jeremy