Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27229

VS 2010 Yammer REST API POST message to wall/feed

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

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

What would i be missing or sending incorrectly?

Viewing all articles
Browse latest Browse all 27229

Trending Articles


FLASHBACK WITH SIRASA FM AT GALGAMUWA 2022


Mp3 Download: Mdu - Mazola


Imitation gun was fired at motorist in Leicester road-rage incident


Ndebele names


MCKINNEY EMALINE “EMMA” OF WES...


Okra & Motia — The Workshop (Prod by Hammer)


Skint TV teen to be sentenced


Moondru Mudichu 19-09-2017 – Polimer tv Serial


YOSVANI JAMES Arrested by Miami-Dade County Corrections on Jan 10, 2017


Stories • Goddess Stepmom



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>