1

我正在开发一个 Sharepoint 托管的应用程序,该应用程序需要使用 javascript 调用 Yammer rest api。已获得访问令牌。只需要在请求标头中传递它。我必须在 app.js 中使用 sharepoint 跨域库。但无论我如何尝试,SP.WebProxy 都会调用端点而不包含该标头。事实证明,sharepoint 故意忽略“Authorizatio”标头。有谁知道另一种方法?谢谢你。

function getYammer() {
   var request = new SP.WebRequestInfo();
   request.set_url("https://www.yammer.com/api/v1/messages/algo.json");
   request.set_headers({ "Authorization": "Bearer abcedfghijk" }); 

  //headers are not sent out to external service
  request.set_method("GET");
  var response = SP.WebProxy.invoke(context, request);
  context.executeQueryAsync(onSuccess, onFail);

  function onSuccess() {
    if (response.get_statusCode() == 200) {

        removePosts('yammer');

        var ResponseBody = JSON.parse(response.get_body());

        for (var i = 0, len = ResponseBody.data.length; i < len; i++) {
            vm.addYammerMessage(ResponseBody.data[i]);
        }
        sortPost();
    }

    else {
        var httpCode = response.get_statusCode();
        var httpText = response.get_body();
        window.console && console.log("Error code returned:" + httpText);
    }
  };

  function onFail() {
    window.console && console.log("Get yammer messages failed:" + response.get_body());
  };

};

4

0 回答 0