Yammer身份验证问题

时间:2017-10-03 09:47:19

标签: json api yammer outsystems

我正在使用Yammer API在Outsystems上创建一个应用程序。问题是Yammer身份验证导致了一些问题。在页面的“OnReady”属性中,我添加了以下代码:

yam.getLoginStatus(
function(response) {
if (response.authResponse) {
  console.log("logged in");
  $parameters.Token = response.access_token.token;
  console.dir(response); //print user information to the console
}
else {
  yam.platform.login(function (response) { //prompt user to login and authorize your app, as necessary
    if (response.authResponse) {
      console.dir(response); //print user information to the console
      console.dir(response.access_token.token);
      $parameters.Token = response.access_token.token;
      console.dir($parameters.Token);
    }
  });
}
}
);

它成功返回一个令牌,我可以使用console.log()进行验证。另外,我添加了一个Login按钮,其OnClick属性中包含相同的代码。

问题是,当我尝试从OnReady执行Get Messages API调用(端点:https://www.yammer.com/api/v1/messages.json)时,它会给我401 Unauthorized访问错误。但是,当我另外使用OnReady,并单击“登录”按钮时,API调用成功。我不明白为什么,因为两个调用收到的令牌完全相同,但是在用户登录两次后它才有效?有什么方法可以纠正这个问题吗?

P.S。我尝试过使用另一个端点(https://api.yammer.com/api/v1/messages.json)。我遇到了同样的问题。

1 个答案:

答案 0 :(得分:0)

尝试在回调函数中添加$resolve()。这样代码将等到完成后再继续下一个jav