2014-03-07 67 views
0

我对yammer API完全陌生。我需要订阅代码,我已经创建了一个代码,但完全没有工作,我被困住了。请帮助我。以下是我使用的代码。如何使用yammer API进行订阅

yam.config({appId: "Kcab3g7Y5P1y1g0H05Bve"}); 
    function post() { 
    yam.getLoginStatus(function(response) { 
    var target_id = '4583632'; 
    var target_user = "user"; 
     if (response.authResponse) { 
      yam.request(
       { 
     url : "https://www.yammer.com/api/v1/subscriptions" 
       , method: "GET" 
       , data: { target_id : target_id,target_type:target_user } 
       , success: function (msg) { 
     for(var key in msg) { 
      var value = msg[key]; 
      alert("success "+value); 
     } 

     } 
       , error: function (msg) { 
        for(var key in msg) { 
      var value = msg[key]; 
      alert("err "+value); 
      } 
       } 
       } 
      ); 
     } 
    }); 
} 

等待答复。谢谢。

回答

0

从您发布的代码中可以清楚地看到您正在尝试执行的操作。以下代码说明了如何检查当前登录的用户是否正在关注(订阅)另一个使用ID为1514517708的Yammer用户。我通过在Yammer网站的Yammer网络中查看用户,并发现了该用户的ID,然后从URL复制用户的feedId。为此,您需要在您的Yammer网络中为用户使用一个ID,并使用您在网络中配置的应用的ID替换appId值。

<html> 
<head> 
    <title>A Yammer App</title> 
    <script src="https://assets.yammer.com/platform/yam.js"></script> 
    <script> 
     yam.config({ appId: "[your appId goes here]" }); 
    </script> 
</head> 
<body> 
    <button onclick='post()'>Check following!</button> 
    <script> 
     function post() { 
      yam.getLoginStatus(function (response) { 
       if (response.authResponse) { 
        check_subscription_to_user(1514517708); 
       } else { 
        yam.login(function (response) { 
         if (!response.authResponse) { 
          check_subscription_to_user(1514517708); 
         } 
        }); 
       } 
      }); 
     }; 

     function check_subscription_to_user(id) { 
      yam.request(
       { 
        url: "https://www.yammer.com/api/v1/subscriptions/to_user/" + id + ".json" 
       , method: "GET" 
       , success: function (msg) { alert("You are following: " + id); } 
       , error: function (msg) { alert("You are not following" + id); } 
       } 
      ); 
     }; 
    </script> 
</body> 
</html> 

有关订阅其他操作,请参阅REST API文档在这里:https://developer.yammer.com/restapi/#rest-subscriptions