Hey all i am trying to understand this mixed up API document that yammer has. I am wanting to POST to a wall comment.
I have its ID (ex. 123456789) and i have my token but i keep getting The remote server returned an error: (401) Unauthorized.
My VB.net code is this:
I'm not sure if i need to do the oauth2 different or before my call? Currently i am just using a webpage (webbrowser) to get my access token.
What would i be missing or sending incorrectly?
I have its ID (ex. 123456789) and i have my token but i keep getting The remote server returned an error: (401) Unauthorized.
My VB.net code is this:
Code:
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader
Dim address As Uri
Dim data As StringBuilder
Dim byteData() As Byte
Dim postStream As Stream = Nothing
address = New Uri("https://www.yammer.com/api/v1/messages.json")
request = DirectCast(WebRequest.Create(address), HttpWebRequest)
request.Method = "POST"
'request.ContentType = "application/x-www-form-urlencoded"
request.ContentType = "application/json"
Dim body As String = "test"
Dim replied_to_id As Integer = 123456789
data = New StringBuilder()
data.Append("access_token=" & HttpUtility.UrlEncode(yammerAPI.userToken))
data.Append("&replied_to_id=" & HttpUtility.UrlEncode(replied_to_id))
data.Append("&body=" & HttpUtility.UrlEncode(body))
byteData = UTF8Encoding.UTF8.GetBytes(data.ToString())
request.ContentLength = byteData.Length
Try
postStream = request.GetRequestStream()
postStream.Write(byteData, 0, byteData.Length)
Finally
If Not postStream Is Nothing Then postStream.Close()
End Try
Try
response = DirectCast(request.GetResponse(), HttpWebResponse)
reader = New StreamReader(response.GetResponseStream())
Debug.Print(reader.ReadToEnd())
Finally
If Not response Is Nothing Then response.Close()
End Try
Code:
Dim url As String = "https://www.yammer.com/oauth2/access_token.json?client_id=" & clientID & "&client_secret=" & clientSecret & "&code=" & authorizedToken
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
Dim reader As StreamReader = New StreamReader(response.GetResponseStream())
Dim o As JObject = JObject.Parse(reader.ReadToEnd)
yammerAPI.userToken = DirectCast(o("access_token")("token").ToString(), String)