I have code that allows me either get messages or send a post to
yammer. I have the access token already so I tried to copy the logic
for my javascript code so I could do the same from a mobile hybrid
application.
The java code does:
String consumerKey = "mykey";
String consumerSecret = "mysecret";
OAuthConsumer consumer = new
CommonsHttpOAuthConsumer( consumerKey, consumerSecret );
consumer.setTokenWithSecret( "key", "secret" );
HttpPost request = new HttpPost( "
https://www.yammer.com/api/
v1/messages.json?body=an%20application%20message" );
consumer.sign( request );
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute( request );
displayResponse( response );
In the response I get a 202 status code and the message is posted in
yammer.
For the javascript I downloaded jsOAuth-1.3.4.js and my code is:
var options;
options = {
enablePrivilege: true,
consumerKey: 'xxx,
consumerSecret: 'xxx'
};
oauth = OAuth(options);
oauth.post( "
https://www.yammer.com/api/v1/streams/
activities.json",
JSON.stringify({ "items": [ { "type": "text",
"text": "Test to see if any notifications are sent from
jsOAuth." } ] })
,function (data) {
alert( "posted result " + data);
}, function (data) {
alert( "post failed " + data);
});
I have debugged it in firefox and I get a success back with a status
code of 0, but no message appears in yammer. I have tried without the
JSON.stringify and also postJSON but I get the same problem.
How can I use jsOAuth when I already have the access token