【问题标题】:yammer js sdk issuesyammer js sdk 问题
【发布时间】:2014-08-28 06:23:53
【问题描述】:

我们在访问 Yammer API 时遇到以下错误。

JQMIGRATE:jQuery.parseJSON 需要一个有效的 JSON 字符串 平台..._sdk.js(第 31 行) 跨域请求被阻止:同源策略不允许读取位于https://www.yammer.com/api/v1/suggestions.json 的远程资源。这可以通过将资源移动到同一域或启用 CORS 来解决。

参考: Yammer JS SDK — problems with CORS 在这里,据说问题已解决。但我们仍然面临这个问题。请确认问题是否已解决。

最好的问候, 参数。

【问题讨论】:

    标签: javascript sdk yammer


    【解决方案1】:

    使用 Yammer JS SDK 时,您需要引用 api.yammer.com 而不是 www.yammer.com/api/v1。

    或者更好的是,如果您想清理 url,您可以省略协议、域和附加内容 (/api/v1),并包含 REST 资源(在您的情况下为建议)和输出格式 (json)。请参见下面的示例:

    yam.getLoginStatus(
      function(response) {
    
    
       if (response.authResponse) {
          console.log("logged in");
          yam.platform.request({
            url: "suggestions.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")
        }
      }
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-26
      • 2022-08-17
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      相关资源
      最近更新 更多