标签接口

标签是除部门外,另一种分类用户的方法,实际上部门也可以打标签的,所以标签也可以给部门分类。

创建标签


创建标签的参考代码:

Dim ul As String = "https://qyapi.weixin.qq.com/cgi-bin/tag/create?access_token={0}"
Dim
hc As New HttpClient(CExp(ul,Functions.Execute("GetQYAccessToken")))
Dim
jo As New JObject()
jo
("tagname") = "UI"
jo
("tagid") = 11
hc
.Content = jo.ToString()
jo
= JObject.Parse(hc.GetData)
If
jo("errcode") = "0" Then
    MessageBox.Show("标签创建成功")

Else

    MessageBox.Show(jo.ToString)

End
If

修改标签名称

例如将tagid为11的标签名改为"UI design",参考代码:

Dim ul As String = "https://qyapi.weixin.qq.com/cgi-bin/tag/update?access_token={0}"
Dim
hc As New HttpClient(CExp(ul,Functions.Execute("GetQYAccessToken")))
Dim
jo As New JObject()
jo
("tagname") = "UI design"
jo
("tagid") = 11
hc
.Content = jo.ToString()
jo
= JObject.Parse(hc.GetData)
If
jo("errcode") = "0" Then
    MessageBox.Show("标签修改成功")

Else

    MessageBox.Show(jo.ToString)

End
If

删除标签

例如要删除tagid为11的标签,参考代码:

Dim ul As String = "https://qyapi.weixin.qq.com/cgi-bin/tag/delete?access_token={0}&tagid={1}"
ul
= CExp(ul,Functions.Execute("GetQYAccessToken"),11)
Dim
hc As New HttpClient(ul)
Dim
jo As JObject= JObject.Parse(hc.GetData)
If
jo("errcode") = "0" Then
    MessageBox.Show("标签删除成功")

Else

    MessageBox.Show(jo.ToString)

End
If

获取标签列表

如果要列出所有标签,可以参考代码:

Dim ul As String = "https://qyapi.weixin.qq.com/cgi-bin/tag/list?access_token={0}"
Dim
hc As New HttpClient(CExp(ul, Functions.Execute("GetQYAccessToken")))
Dim
jo As JObjectJObject.Parse(hc.GetData)
If
jo("errcode") = "0" Then
    Dim sb As New StringBuilder
    For Each jt As JToken In jo("taglist")
        sb.AppendLine(jt("tagid").ToString & "|" & jt("tagname").ToString)
    Next
    MessageBox.Show(sb.ToString)

Else

    MessageBox.Show(jo.ToString)

End
If

增加标签成员

可以一次给多个用户或部门打上某个标签,例如下面的代码,给tagid为1的标签增加了两个成员和一个部门:

Dim ul As String = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers?access_token={0}"
Dim
jo As New JObject
jo
("tagid") = 1
jo
("userlist") = New JArray("zhaoliu","zhansan") '要打标签的成员
jo
("partylist") = New Jarray(9) '要打标签的部门
Dim
hc As New HttpClient(CExp(ul,Functions.Execute("GetQYAccessToken")))
hc
.Content = jo.ToString()
jo
JObject.Parse(hc.GetData)
If
jo("errcode") = "0" Then
    MessageBox.Show("打标签成功")

Else

    MessageBox.Show(jo.ToString)

End
If

获取标签成员

例如要获取tagid为1的标签的所有成员,并保存为一个文本文件,参考代码:

Dim ul As String = "https://qyapi.weixin.qq.com/cgi-bin/tag/get?access_token={0}&tagid={1}"
ul
= CExp(ul,Functions.Execute("GetQYAccessToken"),1)
Dim
hc As New HttpClient(ul)
Dim
jo As JObject= JObject.Parse(hc.GetData)
If
jo("errcode") = "0" Then
    Dim sb As New StringBuilder
    sb.AppendLine("Users:")
    For Each jt As JToken In jo("userlist")
        sb.AppendLine(jt("name").ToString & "|" & jt("userid").ToString)
    Next
    sb.AppendLine("Parties:")
    For Each jt As JToken In jo("partylist")
        sb.AppendLine(jt)
    Next
    FileSys.WriteAllText("c:\data\TagUsers.txt",sb.ToString,False)

Else

    MessageBox.Show(jo.ToString)

End
If

删除标签成员

以下代码从tagid为1的标签中删除了两个用户和一个部门:

Dim ul As String = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers?access_token={0}"
Dim
jo As New JObject
jo
("tagid") = 1
jo
("userlist") = New JArray("zhaoliu","zhansan") '要删除标签的成员
jo
("partylist") = New Jarray(9) '要删除标签的部门
Dim
hc As New HttpClient(CExp(ul,Functions.Execute("GetQYAccessToken")))
hc
.Content = jo.ToString()
jo
JObject.Parse(hc.GetData)
If
jo("errcode") = "0" Then
    MessageBox.Show("删除标签成功")

Else

    MessageBox.Show(jo.ToString)

End
If


本页地址:http://www.foxtable.com/mobilehelp/topics/0225.htm