我公司创建了一个内部使用的Yammer应用程序。我们的应用程序会自动为人们订阅已创建的各种线程。我们发现"订阅"之间存在差异。有人到线程,当用户点击"跟随收件箱"网站上的链接。当我们自动订阅人员时,我们唯一可以看到的事情就是该线程将出现在用户"关注" “主页”选项卡中的部分。将此与用户点击"关注收件箱"链接。从那时起,添加到该线程的任何评论都将显示在用户的收件箱中,并且当发生这种情况时,将向用户发送电子邮件。我们真的希望当我们自动订阅某个线程时,会发生这种情况,但是,REST API中似乎缺少此功能。有谁知道这样做的方法?订阅API端点提供的功能不足以满足我们的目的。
谢谢
P.S。我已将这个问题的链接发送到我的几所大学,他们可能会在我有机会之前做出回应。
答案 0 :(得分:0)
作为经过验证的管理员,可以创建模拟令牌,然后代表用户执行操作,例如加入组/线程。
请注意,对于私人群组,群组管理员仍需要批准新会员
https://developer.yammer.com/docs/impersonation
您可以通过直接向用户添加用户来实现所需的行为。
我使用的C#.Net示例:
// Impersonate user to join group
string ClientID = ConfigurationSettings.AppSettings["ClientID"]; // ClientID of custom app.
string userid = XMLDoc.Root.Element("response").Element("id").Value; // Yammer user id (in this case retreived from a previous API query)
string YammerGroupID = "123456"; // set group id.
string url = "https://www.yammer.com/api/v1/oauth/tokens.json?user_id=" + userid + "&consumer_key=" + ClientID; // impersonation end-point
HttpWebRequest request;
request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("Authorization", "Bearer " + bearer); // Bearer token of verified admin running the custom app.
request.Timeout = 90000;
request.Method = "GET";
request.ContentType = "application/json";
request.Proxy = new WebProxy() { UseDefaultCredentials = true };
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(responseStream);
string UserTokenJSON = reader.ReadToEnd(); // UserOAuth token as a JSON string.
string UserToken = UserTokenJSON.Substring(UserTokenJSON.IndexOf("token") + 8, 22); // Find 'token' in json string.
string temp = UserToken.Substring(UserToken.Length); // there is likely a much better way to parse out the token value, although this works.
temp = UserToken.Substring(UserToken.Length - 1);
temp = UserToken.Substring(UserToken.Length - 2);
if (UserToken.Substring(UserToken.Length) == "\\")
{ UserToken = UserToken.Substring(0, UserToken.Length); }
if (UserToken.Substring(UserToken.Length - 1) == "\"")
{ UserToken = UserToken.Substring(0, UserToken.Length - 1); }
if (UserToken.Substring(UserToken.Length - 2) == "\",")
{ UserToken = UserToken.Substring(0, UserToken.Length - 2); }
string url2 = "https://www.yammer.com/api/v1/group_memberships.json?group_id=" + YammerGroupID; // group membership endpoint,
HttpWebRequest request2;
request2 = (HttpWebRequest)WebRequest.Create(url2);
request2.Headers.Add("Authorization", "Bearer " + UserToken); // Impersonation Token
request2.Timeout = 90000;
request2.Method = "POST";
request2.ContentType = "application/json";
request2.Proxy = new WebProxy() { UseDefaultCredentials = true };
try
{
using (WebResponse response2 = (HttpWebResponse)request2.GetResponse())
{
confirmedstring += " New member: " + Email + "\\r\\n"; // This is used for posting summary back to a Yammer group in further code.
confirmedadditions++;
}
}
catch
{
Errorstring += "Error in adding " + Email + " to group " + YammerGroupID + "\\r\\n";
errors++;
}
}
}