Yammer API - Creating a post on Yammer - yammer

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
yammer

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

Related

Call an Ajax Function after ProgressBar End

I have below ajax which I am calling currenlty on form submit. Based on the return result I am showing an alert message only. What I need to do - show a progressbar for some seconds on body load and at the end of the timer call below ajax and based on the return results hide the progressbar and show a success/error msg. How to do this
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#loginform').submit(function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: 'subscribe.php',
data: $(this).serialize(),
success: function(response)
{
var jsonData = JSON.parse(response);
// user is logged in successfully in the back-end
// let's redirect
if (jsonData.success == "1")
{
alert('You Successfully Subscribed to this Topic!');
}
else
{
alert('Unsubscribed From This Topic Successfully!');
}
}
});
});
});
</script>

Speech Service Authentication Issue on Bot Framework V4

Getting the following error while trying to get a token from Azure Speech Service.
'https://brazilsouth.api.cognitive.microsoft.com/sts/v1.0/issuetoken 401 (Access Denied)'.
Here is the way I'm requesting the token via JavaScript:
const res = await fetch('https://brazilsouth.api.cognitive.microsoft.com/sts/v1.0/issuetoken', { method: 'POST', headers: { Authorization: 'Bearer ' + 'MY_SPEECH_SERVICES_SUBSCRIPTION_KEY'}});
const { authorizationToken } = await res.json();
webSpeechPonyfillFactory = await window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory({ authorizationToken, region });
My bot works fine if I get a token manually via Windows PowerShell though.
What could be possibly wrong?
Thx in advance
Sharing a way to get the token via javascript.
The 'data' variable will be storing the token.
Thanks all for your support!
`<!DOCTYPE html>
<html>
<head>
<title>JSSample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
var params = {
// Request parameters
};
$.ajax({
url: "https://brazilsouth.api.cognitive.microsoft.com/sts/v1.0/issuetoken" + $.param(params),
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","MY_SPEECH_SERVICES_SUBSCRIPTION_KEY");
},
type: "POST",
// Request body
data: "{body}",
})
.done(function(data) {
alert(data);
})
.fail(function() {
alert("error");
});
});
</script>
</body>
</html>`

AJAX post request error 404

I'm trying to do a AJAX post from index.html in the root to my controller. But it is returning 404 Not Found in the firefox console.
index.html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
<script>
$.ajax(
{
url: "api/postData",
type: "POST",
dataType: 'json',
success: function (result) {
console.debug(result);
alert(result);
},
error: function (xhr, status, p3, p4) {
console.debug(xhr);
var err = "Error " + " " + status + " " + p3;
if (xhr.responseText && xhr.responseText[0] == "{")
err = JSON.parse(xhr.responseText).message;
alert(err);
}
});
</script>
</body>
</html>
My Controller:
namespace MyAPI.Controllers
{
[Route("api/postData")]
public class MyAPIController : ApiController
{
[HttpPost]
public bool Post()
{
return true;
}
}
}
Do I need to set something in the RouteConfig.cs?
Thanks
Update your AJAX url to include the method:
url: "api/postData/Post"
You could also try changing:
type: "POST"
to
method: "POST"
Your url is not correct. The url that you have specified leads to the controller itself. And, as you don't have a default index (GET) method you have to specify a route for the method itself:
namespace MyAPI.Controllers
{
[Route("api")]
public class MyAPIController : ApiController
{
[HttpPost]
[Route("postData")]
public bool Post()
{
return true;
}
}
}
this will make your desired url to be the one you are currently using.
Ither option is to remove both of the routes. Then your url will be myapi/post.
Check the Documentation for more information and options.

Ajax is not getting results

I just got into ajax and I cannot understand what is wrong about the code?
index.html
<html>
<head>
<title>Ajax call</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js"></script>
<head>
<body>
<script>
var UserID = 'myname';
var EmailAddress = 'myname#mail.com';
$.ajax({
url: "ajax.php",
type: "get", //send it through get method
data:
{
ajaxid: 4,
UserID: UserID,
EmailAddress: EmailAddress
},
success: function(response)
{
//Do Something
Alert("Sucess");
},
error: function(xhr)
{
//Do Something to handle error
Alert("Failure");
}
});
</script>
</body>
</html>
ajax.php
<?php
foreach ($_GET as $key => $value) {
echo $key . ' => ' . $value . '<br />';
}
?>
After resolving this issue, my main goal is to replace the code in the php file with a function that connects to a SQL Server and retrieve some data using the data sent by the ajax call. I will try this later.
Regards,
Elio Fernandes
Change Alert("smth") to alert("smth")
Then in success function you need to "send" server response to html
success:function(response){
alert('success')
$('body').append(response)
}

Google API Signout Not working

I integrate google login api and It works fine but there is an error in logout.The sign out process is not working.The logged user will not sign out after click the sign out link function.
This is my code:
<meta name="google-signin-client_id" content="here my api .apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
Sign Out
<script>
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
if(profile.getEmail()!="") {
var myKeyVals = { token : googleUser.getAuthResponse().id_token }
$.ajax({
type: "POST",
url: "validate.php",
data: myKeyVals,
dataType: "text",
success : function(data) {
window.location = "page";
}
});
}
}
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
});
}
</script>
Here signOut js function is not working and the page will auto reload and go to adminpage.
This is my document.
Thanks in advance.
this works for me instead of http://localhost/application-name/logoutUser you can add your domain name
document.location.href = "https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=http://localhost/application-name/logoutUser";
This works for me,
Simply modify the signout function as follows,Here carefully note that reload() method is used to reload the current document soon after signout.
<button onclick="myFunction()">Sign Out</button>
<script>
function myFunction() {
gapi.auth2.getAuthInstance().signOut().then(function () {
console.log('User signed out.');
location.reload();
});
}
</script>
May be this will help.
const onGoogleSignOut = () => {
// using google logout redirect
//location.href = 'document.location.href = "https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=' + window.location.href;
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut()
.then(function () {
auth2.disconnect();
console.log('User signed out.');
//location.reload();
});
}
This worked for me. Full JS function code.
The asterisks are just an example of how to define the URL you want to redirect to after the logout is performed.
<button onclick="myFunction()">Sign Out</button>
<script>
function myFunction() {
location.href = 'https://accounts.google.com/Logout?&continue=http://******.com/';
}
</script>
Save this in a HTML file and access it from the browser where you are logged into the account you want to log out of. Can also be placed in a PHP file ETC. AS long as you dont place it in a manner that breaks the existing script.

Resources