问题描述
我正在尝试获取有关Yammer供稿的评论数.
I am trying to get the number of comments for a yammer feed.
我使用了以下查询
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
How can this be resolved? I also tried using api.yammer.com
instead of www.yammer.com
推荐答案
Yammer CORS错误主要是由于缺少JS来源.您需要在代码中定义data-app-id.似乎您的代码段中缺少该内容...
Yammer CORS error are mostly due to missing JS origins. You'd need to define data-app-id in your code. Looks like that's missing from your snippet...
data-app-id="YOUR-APP-CLIENT-ID"
data-app-id是您注册的应用程序的app_id,并确保JS来源到位.
data-app-id, is the app_id of your registered app and ensure JS origin is in place.
此外,建议您不要像这样使用jQuery.getScript(),而是在HTML页面的标题部分中调用脚本:
Also, instead of using jQuery.getScript(), I'd suggest you call the script in the header section of your HTML page like this:
<script type="text/javascript" data-app-id="YOUR-APP-CLIENT-ID" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script>
这篇关于获取yammer feed中的评论数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!