如果您在用户连接到其他网络时使用SDK登录功能登录,则似乎存在问题。所有API调用都失败了,似乎没有办法回到家庭网络进行身份验证。
以下是测试此问题所需的代码:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Yammer Login</title>
<script type="text/javascript" data-app-id="{INSERT APP ID}" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script>
</head>
<body>
<div id="Envelope">
<div><span id="yammer-login"></span></div>
<div><input type="button" onclick="getUserInfo()" value="Get User Info"></div>
<script>
yam.connect.loginButton('#yammer-login',
function (resp) {
console.log(resp);
});
function getUserInfo() {
yam.platform.request({
url: 'users/current.json',
method: "GET",
success: function (r) { console.log("GOT RESPONSE"); console.log(r); },
error: function (r) { console.log(r.statusText) }
});
}
</script>
</div>
</body>
</html>
如果用户登录其家庭网络,则登录代码有效,您可以按此按钮获取用户信息(注意javascript来源已正确配置)。
您进入yammer界面并选择另一个不再有效的网络。
以下是控制台输出的内容:
GET https://www.yammer.com/platform/login_status.json?
client_id={Client ID} 403 (Forbidden)
platform_js_sdk.js:26 XHR finished loading: GET "https://www.yammer.com/platform/login_status.json?client_id={ClientID}".
test.php:18 Object {access_token: Object, success: true, status: "connected", authResponse: true}
api.yammer.com/api/v1/users/current.json:1 GET https://api.yammer.com/api/v1/users/current.json
test.php:1 XMLHttpRequest cannot load https://api.yammer.com/api/v1/users/current.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://webserver.com' is therefore not allowed access. The response had HTTP status code 401.
test.php:26 error
api.yammer.com/api/v1/users/current.json:1 GET https://api.yammer.com/api/v1/users/current.json
test.php:1 XMLHttpRequest cannot load https://api.yammer.com/api/v1/users/current.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://webserver.com' is therefore not allowed access. The response had HTTP status code 401.
test.php:26 error
正在使用的登录令牌似乎属于另一个网络,因此访问受到限制。
答案 0 :(得分:1)
基于Yammer REST API: How to get access tokens for external networks? 您需要申请部署到全球应用程序目录。通过电子邮件向Biz Dev代表指定您的应用需要全局访问(即使没有在App Directory中发布)。这解决了这个问题。
请参阅http://about.yammer.com/assets/yammer-apps-next-steps.ppt
的幻灯片5