Yammer JavaScript SDK - 'Access-Control-Allow-Origin'

Yammer JavaScript SDK - 'Access-Control-Allow-Origin' issue

本文关键字:Access-Control-Allow-Origin JavaScript SDK Yammer      更新时间:2023-09-26

我试图使Yammer API请求按指令在这里:https://developer.yammer.com/yammer-sdks/#javascript-sdk。当我运行这个例子时:

yam.getLoginStatus(
  function(response) {
    if (response.authResponse) {
      console.log("logged in");
      yam.platform.request({
        url: "https://www.yammer.com/api/v1/users.json",     //this is one of many REST endpoints that are available
        method: "GET",
        data: {    //use the data object literal to specify parameters, as documented in the REST API section of this developer site
          "letter": "a",
          "page": "2",
        },
        success: function (user) { //print message response information to the console
          alert("The request was successful.");
          console.dir(user);
        },
        error: function (user) {
          alert("There was an error with the request.");
        }
      });
    }
    else {
      alert("not logged in")
    }
  }
);

我在本地主机上这样做,我得到以下错误:

"XMLHttpRequest cannot load https://www.yammer.com/api/v1/users.json?letter=a&page=2&_=1401954073159. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access."

你知道怎么解决这个问题吗?

还有一点。我不能在这里指定额外的头,因为这个调用是作为'OPTIONS'而不是'GET'请求方法执行的。

希望有人有相同的问题与Yammer最新的API,并能够解决它。

谢谢

确保更新您的Yammer apps JS Origins以匹配您正在测试的环境主机名。

你可以在这个链接中配置这些源:

https://www.yammer.com/client_applications

点击你的应用程序,然后点击"基本信息"

使用主机名为"api.yammer.com"而不是"www.yammer.com"。我相信文档需要更新,我会更新的。

或者,您可以使用yam.platform.request('users.json')而不是yam.request('https://api.yammer.com/api/v1/users.json'),您不必调整主机名

将应用程序url添加到yammer application basicinfo中的"Javascript Origins" .