【问题标题】:get number of comments in yammer feed获取 yammer 提要中的评论数
【发布时间】:2015-11-27 05:32:48
【问题描述】:

我正在尝试获取 yammer 提要的 cmets 数量。

我使用了下面的查询

jQuery.getScript("https://c64.assets-yammer.com/assets/platform_js_sdk.js",function(){
console.log("script loaded");
  var commentCnt = 0;
      yam.platform.request(
          { url: "https://www.yammer.com/api/v1/messages/open_graph_objects/"+ogID+".json"
          , method: "GET"
          , data: {"body": "This Post was Made Using the Yammer API.  Welcome to the Yammer API World."}
          , success: function (msg) {
                    if (msg) {
                        jQuery.each(msg.messages, function (index, element) {
                            commentCnt++;
                        });
                    }
                    //adds the count to the webpage.
                    jQuery("div#commentCnt").text(commentCnt);
                }
          , error: function (msg) { 
                        //console.log("message lookup failed");
            }
      });
});

这返回了

XMLHttpRequest cannot load http://myApiUrl/. No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'null' is therefore not allowed access

如何解决?我也尝试使用api.yammer.com 而不是www.yammer.com

【问题讨论】:

    标签: javascript jquery sharepoint yammer


    【解决方案1】:

    Yammer CORS 错误主要是由于缺少 JS 源。您需要在代码中定义 data-app-id。看起来您的 sn-p 中缺少此功能...

    data-app-id="YOUR-APP-CLIENT-ID" 
    

    data-app-id,是您注册应用的 app_id,并确保 JS 来源到位。

    另外,我建议您不要使用 jQuery.getScript(),而是在 HTML 页面的标题部分调用该脚本,如下所示:

    <script type="text/javascript" data-app-id="YOUR-APP-CLIENT-ID" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多