MYOBCommunity
Partner Zone
|
|
Partner Zone

Desktop Solution in VB using AccountRight API

This thread is now closed to new comments.
Some of the links provided in this thread may no longer be available or relevant.
If you have a question please start a new post.
1 REPLY 1
Former Staff DeveloperJack
141 Posts
Former Staff
Australia
DeveloperJack
Former Staff

141Posts

31Kudos

21Solutions

Re: Desktop Solution in VB using AccountRight API

Hi there @Henzard,

 

In this set of code the exRefresh exception should contain a little more information about the error including an 'errors' field. I'd recommend looking into that variable with your debugger to figure out what the error is.

 

If you're still having trouble, can you share some screenshots of your debugging to the support team via developers@myob.com and we can take a closer look there.

 

Cheers!

Jack

Jack Skinner
MYOBapi Evangelist

Are you a developer? Check out http://developer.myob.com
Looking for an Add-on? Check out http://myob.com/addons/
Highlighted
Partner Henzard
1 Post
Partner
Henzard
Partner

1Posts

0Kudos

0Solutions

Desktop Solution in VB using AccountRight API

Hi,

 

We createted a desktop app and need the login to persist over time we really need some help with the code. We are saving the auth token in a DB as a json serialized token and then load it up before doing a trasaction. When it expires we renew it but for some reason it need to do a fresh login every few days. Can someone please help.

 

'Initialising the Connection 

myConfiguration = New ApiConfiguration(DeveloperKey, DeveloperSecret, "http://desktop")
myOAuthKeyService = New OAuthKeyService()

 

'Loading from the DB

Dim authTokens As New OAuthTokens
If (mobjConfig.MYOBToken IsNot Nothing AndAlso mobjConfig.MYOBToken.Length > 0) Then
authTokens = Newtonsoft.Json.JsonConvert.DeserializeObject(Of OAuthTokens)(mobjConfig.MYOBToken)
End If

 

'Setting the Token
Dim oauthService As New OAuthService(myConfiguration)
myOAuthKeyService.OAuthResponse = authTokens

 

'Check if it's Expired

If myOAuthKeyService.OAuthResponse.HasExpired = True Then

       Dim _oauthService As New OAuthService(myConfiguration)
       Dim _tokens As New OAuthTokens
       Dim _bolError As Boolean = False
       'Try and refresh tokens first ...
       Try

              _tokens = oauthService.RenewTokens(myOAuthKeyService.OAuthResponse)
              _bolError = False
       Catch exRefresh As Exception
              _bolError = True 'How do I prevent This ???

       End Try

       'If it does not refresh create a new token 

       If _bolError = True Then
              Try
                     _tokens = oauthService.GetTokens(OAuthLogin.GetAuthorizationCode(myConfiguration))
                     _bolError = False
              Catch exNewToken As Exception
                     _bolError = True

              End Try

       End If

       myOAuthKeyService.OAuthResponse = _tokens
       Dim strTokens As String = JsonConvert.SerializeObject(_tokens)

       mobjConfig.MYOBToken = strTokens
       mobjConfig.SaveConfig(mobjGlobals)
End If

 

Kind Regards

Remember I consult on a per hour basis. Contact me if your need me to fix the problem. $45 per hour.

We can do a 30 min free consultation via Skype.

Henzard Kruger
Certified Advisor and Full Stack developer
Picahoo cc - 0711304241 - henzard@picahoo.co.za
Skype: henzard, Gtalk: henzardkruger@gmail.com
Quality is remembered long after the price is forgotten

I abide by the 3 message rule. After 3 messages we skype.

 

Didn't find your answer here?
Try using advanced search to find a post more easily Advanced Search
or
Get the conversation started and make a new post Start a Post