Hi all,
Trying to swap my app from API 1.0 to 2.0, and I cant get past the token
request - getting Authorisation (401) error. My app is authorised,
appears in my Freeagent application list, and all seems good. But when my
app gets the token, no matter what I do, I cant get past a 401
authorisation error. Not sure if its the userid/password which is wrong
(picked up from the developer dashboard), or the passed in authorisation
code (which as instructed, is passed back following authorisation)
Note - the auth code and user/password codes have been changed from the
ACTUAL values, but are pretty much in the format as being supplied (length,
look/feel etc).
Note - the hard coding and odd settings (PreAuthenticate, Protocol version,
etc) are me trying to get the blasted thing working (following advice I
found on the web). Clearly, in my app, the auth codes wont be hard coded
- but just trying to get past the 401 error at this point.
Any clues/advice?
Dim URL As String
URL = "https://api.freeagent.com/v2/token_endpoint"
' Create the data to send
Dim data As StringBuilder = New StringBuilder()
data.Append(“grant_type=authorization_code&code=1Boeu6tpoeteCF8YAijVCendLiKY1mDbFnJNsw7nbS”)
<----- HARD CODED TO TEST WHERE ITS GOING WRONG
' Create a byte array of the data to be sent
Dim byteArray As Byte() =
UTF8Encoding.UTF8.GetBytes(data.ToString())
' Setup the Request
Dim request As HttpWebRequest = WebRequest.Create(URL)
request.PreAuthenticate = True
request.Method = "POST"
request.ProtocolVersion = HttpVersion.Version10
request.ContentType =
“application/x-www-form-urlencoded;charset=UTF-8”
request.ContentLength = byteArray.Length
request.Credentials = New
NetworkCredential(“PjdASDASDASccpVk4iag”, “KvSDFSDFDSFJl2dKOzaOg”)
<---------- HARD CODED TO TEST WHERE ITS GOING WRONG, ITS THE ‘*OAuth
identifier’ *AND OAuth secret VALUES
' Write data
Dim postStream As Stream = request.GetRequestStream()
postStream.Write(byteArray, 0, byteArray.Length)
postStream.Close()
' Send Request & Get Response
Response = request.GetResponse() <------ 401 error here!!!!!!