0 Replies - 545 Views - Last Post: 29 August 2013 - 11:20 AM Rate Topic: -----

#1 StealthRT  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 65
  • Joined: 29-September 08

Yammer REST API POST message to wall/feed

Posted 29 August 2013 - 11:20 AM

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:
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

   postStream = request.GetRequestStream()
   postStream.Write(byteData, 0, byteData.Length)
   If Not postStream Is Nothing Then postStream.Close()
End Try

   response = DirectCast(request.GetResponse(), HttpWebResponse)
   reader = New StreamReader(response.GetResponseStream())
   If Not response Is Nothing Then response.Close()
End Try

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.
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)

What would i be missing or sending incorrectly?

Is This A Good Question/Topic? 0
  • +

Page 1 of 1