sharepoint 2013 Sp.Webproxy.invoke不包含标头

时间:2014-01-31 15:33:28

标签: sharepoint sharepoint-2013 yammer

我正在开发一个需要通过javascript调用Yammer rest api的Sharepoint托管应用。已获取访问令牌。只需要在请求标头中传递它。我必须在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());
  };

};

0 个答案:

没有答案