Reputation: 21
I'm trying to use the Yammer API to create a post on Yammer, I have the following code:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/TR/html5/">
<head>
<meta charset="utf-8" />
<title>YammerNotification - Version 1</title>
<script src="https://assets.yammer.com/platform/yam.js"></script>
<script>
yam.config({ appId: "APP-ID" });
</script>
</head>
<body>
<button onclick='post()'>Post on Yammer!</button>
<script>
function post() {
yam.getLoginStatus(function (response) {
if (response.authResponse) {
yam.request(
{
url: "https://www.yammer.com/api/v1/messages.json"
, method: "POST"
, data: { "body": "This Post was Made Using the Yammer API. Welcome to the Yammer API World." }
, success: function (msg) { alert("{Post was Successful!}: " + msg); }
, error: function (msg) { alert("Post was Unsuccessful..." + msg); }
}
)
} else {
yam.login(function (response) {
if (!response.authResponse) {
yam.request(
{
url: "https://www.yammer.com/api/v1/messages.json"
, method: "POST"
, data: { "body": "This Post was Made Using the Yammer API. Welcome to the Yammer API World." }
, success: function (msg) { alert("{Post was Successful!}: " + msg); }
, error: function (msg) { alert("Post was Unsuccessful..." + msg); }
}
);
}
});
}
});
}
</script>
</body>
</html>
Although what would my APP ID be? And how do I tell it what group I want to put a post to?
Any suggestions are greatly appreciated
Upvotes: 2
Views: 6103
Reputation: 952
...what would my APP ID be?
You'd need to register an app as documented here - https://developer.yammer.com/introduction/#gs-registerapp and your APP ID is the client ID's value
And how do I tell it what group I want to put a post to?
Specify the groupID in your json data input:
data: {
"body": "This Post was Made Using the Yammer API. Welcome to the Yammer API World."
,"group_id" : groupID
}
See full sample code here - http://blogs.technet.com/b/israelo/archive/2014/10/21/yammer-js-sdk-for-dummies.aspx
Upvotes: 4