获取素材列表

获取素材列表的接口参考:

https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_materials_list.html

你可以通过下面的代码,获取所有素材信息保存在Materials表中:

DataTables
("Materials").DataRows.Clear()
Dim
typs() As String = {"image","voice","video","news"} '""
For
Each typ As String In typs
    Dim ur As String = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token={0}"
    Dim st As New
Date(1970,1,1,8,0,0)
    Dim offset As Integer = 0
    Do
        Dim hc As new HttpClient(CExp(ur, Functions.Execute("GetAccessToken")))
        Dim jo As New JObject
        jo("type") = typ
        jo("offset") = offset
        jo("count") = 20
'一次最多获取20个
        hc.Content = jo.ToString()
        jo = JObject.Parse(hc.GetData)
        If jo("errcode") Is Nothing Then
            If CInt(jo("item_count")) = 0 Then
                Exit Do
            End If
            For Each item As JToken In jo("item")
                Dim dr As DataRow = DataTables("Materials").AddNew
                dr("Type") = typ
                dr("MediaID") = item("media_id")
                dr("FileName") = item("name")
                dr("URL") = item("url")
                dr("UpdateTime") = st.AddSeconds(item("update_time"))
                If item("content") IsNot Nothing Then
                    dr("Content") = item("content")("news_item").ToString()
                End If
            Next
            offset = offset + CInt(jo("item_count"))
       
Else
            MessageBox.Show(jo.Tostring) '显示错误信息
            Exit Do
        End If
   
Loop

Next
DataTables
("Materials").Save()


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