2 Replies - 921 Views - Last Post: 09 February 2015 - 07:04 AM Rate Topic: -----

#1 StealthRT  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 68
  • 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

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


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? 1
  • +

Replies To: Yammer REST API POST message to wall/feed

#2 michaltadeas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-February 15

Re: Yammer REST API POST message to wall/feed

Posted 09 February 2015 - 04:00 AM

Dear StealthRT,
I just want to ask, if you got the wall message work the way you described?
Thank you, michaltadeas
Was This Post Helpful? 0
  • +
  • -

#3 StealthRT  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 68
  • Joined: 29-September 08

Re: Yammer REST API POST message to wall/feed

Posted 09 February 2015 - 07:04 AM

Sadly i have not. I just gave up on their API last year sometime. Haven't picked it back up since. Hopefully they have improved it since it seems Microsoft owns the company now.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1