2014-08-28 61 views
3

訪問Yammer API時遇到以下錯誤。yammer js sdk問題

JQMIGRATE:jQuery.parseJSON需要一個有效的JSON字符串 platfor ..._ sdk.js(第31行) 跨來源請求阻止:同源策略不允許在https://www.yammer.com/api/v1/suggestions.json讀取遠程資源。這可以通過將資源移動到相同的域或啓用CORS來解決。

Ref: Yammer JS SDK — problems with CORS 在這裏,據說問題已解決。但我們仍然面臨這個問題。請確認問題是否已解決。

此致敬禮, Parameswaran。

回答

0

使用Yammer JS SDK時,您需要引用api.yammer.com而不是www.yammer.com/api/v1。或者更好的是,如果你想清理url,你可以省略protocol,domain和extras(/ 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") 
    } 
    } 
);