Skip to content

Instantly share code, notes, and snippets.

@sandeeptalabathula
Forked from nmccarthy/gist:4727823
Created February 8, 2013 18:45
Show Gist options
  • Save sandeeptalabathula/4741049 to your computer and use it in GitHub Desktop.
Save sandeeptalabathula/4741049 to your computer and use it in GitHub Desktop.
<script type="text/javascript" data-app-id="YOUR-APP-ID" src="https://assets.yammer.com/platform/yam.js"></script>
<script>
yam.getLoginStatus(function(response) {
if (response.authResponse)
{
//GET THE TOKENS FOR ALL MY NETWORKS
yam.request({
url: "https://www.yammer.com/api/v1/oauth/tokens.json",
method: "GET",
success: function(msg) {
var access_token = "";
for (var i=0; i < msg.length; i++) {
//GRAB THE TOKEN FOR THE DESIRED NETWORK
if (msg[i].network_permalink == "TARGET_NETWORK_PERMALINK")
{
console.log(msg[i].network_permalink)
access_token = msg[i].token;
break;
}
};
//request messages for the target network
yam.request({
url: "https://www.yammer.com/api/v1/messages.json",
method: "GET",
beforeSend: function (req) { //send the access_token in the HTTP header
req.headers.Authorization = "Bearer " + access_token;
},
success: function(msg) {
console.log(msg);
},
error: function(msg) {
console.log(msg);
}
});
},
error: function(msg) {
console.log(msg);
}
});
}
else
{
yam.login(function(response) {
if (response.authResponse)
{
console.log("you're logged in now, please reload the page");
}
});
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment