我所有的yammer请求都返回Access Denied

时间:2014-09-18 17:31:28

标签: yammer

我在我的应用程序中尝试了大量REST端点,并且所有这些端点都拒绝访问。我为此感到困惑。我已经仔细检查了应用程序ID,我知道我已登录。这是完整的来源:

<body>
    <button onclick='post()'>Post on Yammer!</button>
    <button onclick='loginStatus()'>Login Status</button>
    <button onclick='postActivity()'>Post Activity</button>
    <button onclick='getSuggestions()'>Get Suggestions</button>
    <button onclick='getUser()'>Get User</button>
    <button onclick='getMessages()'>Get Messages</button>
    <button onclick='search()'>Search</button>`enter code here`
    <button onclick='getGroups()'>Groups</button>
    <script type="text/javascript">
//<![CDATA[
        function post() {
            yam.getLoginStatus(function (response) {
                if (response.authResponse) {
                    alert(1);
                    yam.request({
                        url: "https://www.yammer.com/api/v1/messages.json",
                        method: "POST",
                        data: { "body": "HelloTest" },
                        success: function (msg) { alert("Post was Successful!: " + msg); },
                        error: function (msg) { Console.dir(msg);}

                    });
                } else {
                    alert(2);
                    yam.login(function (response) {
                        if (!response.authResponse) {
                            yam.request({
                                url: "https://www.yammer.com/api/v1/messages.json",
                                method: "POST",
                                data: { "body": "HelloTest" },
                                success: function (msg) { alert("Post was Successful!: " + msg); },
                                error: function (msg) {  Console.dir(msg); }
                            });
                        }
                    });
                }
            });
        }

        function loginStatus() {
            yam.getLoginStatus(
  function (response) {
      if (response.authResponse) {
          alert("logged in");
          console.dir(response); //print user information to the console
      }
      else { //authResponse = false if the user is not logged in, or is logged in but hasn't authorized your app yet
          alert("logged out");
      }
  }
);
        }

        function postActivity() {
            yam.request({
                url: "https://www.yammer.com/api/v1/activity.json",
                method: "POST",
                data: {
                    "activity": {
                        "actor": {
                            "name": "Jeff Kirkham",
                            "email": "garthf@retailv3dev2.onmicrosoft.com"
                        },
                        "action": "create",
                        "object": {
                            "url": "https://www.yammer.com/retailv3dev2.onmicrosoft.com",
                            "title": "Lunch Meeting"
                        },
                        "message": "Hey, let’s get sushi!",
                        "users": [
                        {
                            "name": "Jeff Kirkham",
                            "email": "garthf@retailv3dev2.onmicrosoft.com"
                        }
                        ]
                    }
                },
                success: function (msg) { alert("Post was Successful!: " + msg); },
                error: function (msg) { console.dir(msg); }
            })
        }

        function getUser() {
            yam.request({
                url: "https://www.yammer.com/api/v1/users/current.json",
                method: "GET",
                success: function (msg) { alert("Get was Successful!: " + msg); },
                error: function (msg) { console.dir(msg); }
            })
        }

        function getMessages()
        {
            yam.request({
                url: "https://www.yammer.com/api/v1/messages.json",
                method: "GET",
                success: function (msg) { alert("Get was Successful!: " + msg); },
                error: function (msg) { console.dir(msg); }
            })
        }

        function search()
        {
            yam.request({
                url: "https://www.yammer.com/api/v1/search.json",
                method: "GET",
                search: "Marketing",
                success: function (msg) { alert("Get was Successful!: " + msg); },
                error: function (msg) { console.dir(msg); }
            })
        }

        function getGroups() {
            yam.platform.request({
                url: "groups.json?mine=1",
                method: "GET",
                data: {},
                success: function (msg) { alert("Get was Successful!: " + msg); },
                error: function (msg) { console.dir(msg); }
            })
        };

        function getSuggestions() {
            yam.getLoginStatus(
  function (response) {
      if (response.authResponse) {
          console.log("logged in");
          yam.platform.request({
              url: "suggestions.json",     //this is one of many REST endpoints that are available
              method: "GET",
              data: {    //use the data object literal to specify parameters, as documented in the REST API section of this developer site
                  "letter": "a",
                  "page": "2",
              },
              success: function (user) { //print message response information to the console
                  alert("The request was successful.");
                  console.dir(user);
              },
              error: function (user) {
                  alert("There was an error with the request.");
                  console.dir(user);
              }
          });
      }
      else {
          alert("not logged in")
      }
  }
);
        }


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

</body>

1 个答案:

答案 0 :(得分:0)

注意:如果您将脚本的范围缩小到一个无法按预期工作的单个函数,那么如果您将脚本的范围缩小到适当的范围,那么它将更有用,而不是为其他人调试一个非常长的脚本。

我注意到的一点是你打电话给www.yammer.com/api/v1 /.

由于CORS,我们限制了对www.yammer.com/api/v1端点的JS SDK调用。相反,省略主机名并只关注端点,就像您在suggest.json示例中所做的那样。