如何使用REST API和Yammer用户ID获取Yammer用户信息

时间:2017-04-17 10:18:48

标签: javascript rest yammer

我正在使用Yammer REST API来提取用户信息,这些信息在我对Yammer API进行硬编码时非常有效。

我正在尝试使用输入框,以便脚本更灵活,但在将用户ID变量传递给Yammer API时,我一直遇到问题。

因为我从函数传递到函数它不起作用,我被建议使用localStorage,但这似乎与变量有同样的问题。 我不知道我做错了什么?

<html>
  <head>  

  </head> 
<body>

<form id="frm1" action="#" method="post">
  Yammer ID: <input type="text" name="y_id"><br><br>
  <input type="submit" onclick="yam_inp()" value="Submit">
</form> 


<span id="yammer-login"></span>

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

<script>

function yam_inp() {
frm_i=document.getElementById("frm1");
//result=frm_i.elements[0].value; //unable to pass from funtion to function so using local storage
localStorage.yammer_id=frm_i.elements[0].value; // line 23, Unable to set property 'yammer_id' of undefined or null reference
//localStorage.setItem("yammer_id", frm_i.elements[0].value);
alert (result);
}

yam.getLoginStatus(
  function (response) {
    if (response.authResponse) {
      console.log("logged in");
      yam.platform.request({
        url: "users/"+localStorage.yammer_id+".json",    //line 32, Unable to get property 'yammer_id' of undefined or null reference 
        method: "GET",
        data: {    
          "User_Id": localStorage.yammer_id,
        },
        success: function (user) { //print message response information to the console
          // alert("The request was successful.");
          //str = JSON.stringify(user);
          str = JSON.stringify(user, null, 4); // (Optional) beautiful indented output.
          document.write(str);
          //console.dir(user);
        },
        error: function (user) {
          alert("There was an error with the request.");
        }
      });
    }
    else {
      alert("not logged in")
    }
  }

);
</script>

我一直得到第32行:Unable to get property 'yammer_id' of undefined or null reference,这是我在localStorage之前得到的结果变量,所以这违背了localStorage的目标,除非我没有正确使用它。

0 个答案:

没有答案