danielcrenna/hammock — Issue #61: API calls failing with LinkedIn
Author: pauledavey
Created: 2012-01-05 13:45:59+00:00
State: open

Hi, I have got some code working using Hammock to connect to LinkedIn and get the correct tokens in reply, but I cannot get any more information out from the API. I always recieve an error stating that the contntI am trying to get cannot be found. I would appreciate any and all help if possible as this has been causing me grief for a couple of days now!

The error I get back is as follows (using the code that I have provided below)

404
1325771030285
SIFHIG3NFH
0
Could not find person based on: ~

And I am trying to get information on the current authenticated user as per described at the following link:
https://developer.linkedin.com/documents/profile-api

Thanks in advance,

Paul

' *********Code as follows:

Imports Hammock
Imports Hammock.Authentication.OAuth
Imports Hammock.Authentication
Imports System.Text

Public Class Form1

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim mycredentials As New Hammock.Authentication.OAuth.OAuthCredentials
With mycredentials
.CallbackUrl = "oob"
.ConsumerKey = "xxxxxx"
.ConsumerSecret = "xxxxxxx"
.Type = Authentication.OAuth.OAuthType.RequestToken
End With

Dim myClient As New RestClient
With myClient
.Authority = "https://api.linkedin.com/uas/oauth"
.Credentials = mycredentials
.Path = "https://api.linkedin.com/uas/oauth/requestToken"
End With

Dim myRequest As New RestRequest
With myRequest
.Path = "requestToken"
End With

Dim myResponse As RestResponse = myClient.Request(myRequest)
Dim myContent() As String = Split(myResponse.Content, "&")
If Not LCase(myResponse.StatusDescription) = "ok" Then
MsgBox("Could not obtain Request Token")
Exit Sub
Me.Dispose()
End If

' We need to ask the user for a Pin to authorise the application.
' Create a string URL to take the user to the LinkedIn Application Authorisation Page
Dim _authStringURL As String = "https://www.linkedin.com/uas/oauth/authorize?" & myContent(0).ToString
Dim _pinCode As String = Nothing

System.Diagnostics.Process.Start(_authStringURL)
_pinCode = InputBox("Please enter the pin as provided on the authorisation page")

' Update our credentials
With mycredentials
.Token = myContent(0).Substring((InStr(myContent(0), "=")))
.TokenSecret = myContent(1).Substring((InStr(myContent(1), "=")))
.Type = OAuthType.AccessToken
.SignatureMethod = OAuthSignatureMethod.HmacSha1
.Version = "1.0"
.ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader
.Verifier = _pinCode
End With

Dim client As New RestClient()
client.Authority = "https://api.linkedin.com/uas/oauth"
client.Credentials = mycredentials
client.Method = Web.WebMethod.Post

Dim request As New RestRequest
request.Path = "/accessToken"

Dim response As RestResponse = client.Request(request)

Dim content As String = response.Content
Dim _accessToken As String = myContent(0).Substring((InStr(myContent(0), "&")))
Dim _accessSecret As String = myContent(1).Substring((InStr(myContent(1), "&")))

Try
Dim mynewClient As New RestClient()
With mynewClient
.Authority = "http://api.linkedin.com/v1/people"
.Credentials = mycredentials
.Method = Web.WebMethod.Get
'.Path = "url=http://uk.linkedin.com/in/pauledavey"
End With

Dim newrequest As RestRequest = New RestRequest
newrequest.Path = "~"
mycredentials.Verifier = Nothing
newrequest.Credentials = mycredentials

' AT THIS POINT I CHECK THE NEWRESPONSE I SEE THE 'CONTENT' CONTAINS THE ABOVE
Dim newresponse As RestResponse = mynewClient.Request(newrequest)

Catch ex As Exception
MsgBox("!")
End Try

End Sub