Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > API Authentication >

Can't retrieve an access token

Started by Ian Pook -   in API Authentication

This should be simple but....

We can get a request token no problem but when we plug in the responses to try and retrieve an access token the webresponse always returns nothing. We are using the DevDefined library and VB.Net.

' Use the request token and verification code to get an access token
Dim httpRequest As OAuthHttpWebRequest = New OAuthHttpWebRequest()
httpRequest.ConsumerToken = New OAuthToken() With {.Token = GlobalVariables.XeroConsumerKey, .TokenSecret = GlobalVariables.XeroConsumerSecret}
httpRequest.Token = New OAuthToken() With {.Token = requestToken, .TokenSecret = requestSecret}
httpRequest.SetUri("https://api.xero.com/oauth/Authorize?oauth_verifier=" & userEnteredVerificationCode)

Dim accessTokenKey = ""
Dim accessTokenSecret = ""

Using response As WebResponse = httpRequest.GetResponse()
Dim accessTokenResponse As OAuthTokenResponse = New OAuthTokenResponse(response)
accessTokenKey = accessTokenResponse.Token.Token <== returns nothing
accessTokenSecret = accessTokenResponse.Token.TokenSecret <== returns nothing
End Using

As far as we can see the .ConsumerToken, .Token and .SetUri properties of the web request are all formatted correctly with the verification code that our user has input. However we've had to cobble our code together from some of the CS examples as there are no VB examples available to get us started!

Any help much appreciated.

PS Please, please get some VB. Net examples in the API reference, there are millions of us out here!!
Best Reply
Hi Ian,

From the code snippets that you've written, it looks like you're using the raw OAuth library. If you're still at the start of an integration project with XeroAPI, you might want to consider using the XeroAPI.Net wrapper library.

In the XeroAPI.Net project, I've just added a sample VB.Net console app that connects to the Xero API as a public app. The source code is on github:

Having said that, just looking at your code... it appears that you might be incorrectly calling the /oauth/Authorize method to get the access token. There is a separate method /oauth/AccessToken that should be used for swapping the request token and verification code for an access token.


Dan Barratt (Xero Staff)