-
-
Save sandeeptalabathula/4741049 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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