Foxtable(狐表)用户栏目专家坐堂 → 帮助文件代码运行报错 求解


  共有3563人关注过本帖树形打印复制链接

主题:帮助文件代码运行报错 求解

帅哥哟,离线,有人找我吗?
xa139
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:282 积分:2835 威望:0 精华:0 注册:2019/4/23 11:17:00
帮助文件代码运行报错 求解  发帖心情 Post By:2020/9/27 11:25:00 [只看该作者]


DataTables("WXUsers").DataRows.Clear()
Dim ul As String = "https://api.weixin.qq.com/cgi-bin/user/get?access_token={0}&next_openid={1}"  '获取用户OpenID列表接口
Dim
il = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token={0}" '批量获取用户信息接口
Dim
nms() As String = {"openid","nickname","sex","city","country","province","headimgurl","groupid","remark","language"} '列名
Dim
hc As New HttpClient(CExp(ul, Functions.Execute("GetAccessToken"),""))
Dim
ids As New List(of String) 'OpenId集合,每次获取10000
Dim
ba As New Jarray '准备用来获取用户信息的OpenId列表,一次不能超过100
Dim
jo As JObject = JObject.Parse(hc.GetData)
Do
'循环获取,一次只能获取10000OpenID
    If jo("errcode") Is Nothing Then
        Dim cnt As Integer = jo("count")
        If cnt = 0 Then
'
如果已经获取完所有用户'
            Exit Do
        End If
        For Each jk As JToken  In jo("data")("openid")
            ids.Add(jk)
        Next
        For i As Integer = 0 To ids.Count - 1 
'
循环获取用户详情,一次不能超过100个用户
            Dim uo As New JObject
            uo("openid") = ids(i)
           
ba.Add(uo)
            If ba.Count = 100 OrElse i = ids.Count - 1 Then '每满100个就获取一次
                Dim bo As New Jobject
               
bo("user_list") = ba
                hc = New HttpClient(CExp(il, Functions.Execute("GetAccessToken")))
                hc.Content = bo.ToString()
                Dim ro As JObject = JObject.Parse(hc.GetData)
                If ro("errcode") Is  Nothing Then
                    Dim ia As JArray = ro("user_info_list")
'
获取的用户信息列表
                    For Each jt As JToken In ia
                        Dim dr As DataRow = DataTables("WXUsers").Find("openid = '" & jt("openid").ToString() & "'")
                        If dr Is Nothing Then
                            dr = DataTables("WXUsers").AddNew()
                        End If
                        For Each nm As String In nms
                            dr(nm) = jt(nm)
                        Next
                        dr("tagid_list") = CompressJSON(jt("tagid_list"))
                    Next
                Else
                    MessageBox.Show(ro.ToString)
                    Exit For
                End If
                ba.Clear()
'
清除集合,准备获取下一批用户详情,每批只能100.
            End If
        Next
        ids.Clear
'
清除已经获取的OpenID.,准备接收下一批OpenID
        hc =  New HttpClient(CExp(ul, Functions.Execute("GetAccessToken"),jo("next_openid").Tostring)) 
'
获取下一批OpenID
        jo = JObject.Parse(hc.GetData)
    Else
        MessageBox.Show(jo.ToString)
        Exit Do
    End
If

Loop
DataTables
("WXUsers").Save() 
帮助文件内 微信get用户信息
执行报错 
图片点击可在新窗口打开查看此主题相关图片如下:1601176781(1).png
图片点击可在新窗口打开查看
求解

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:111393 积分:567029 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/9/27 11:53:00 [只看该作者]

提示是没有权限使用api。确认客户端外网ip已经加入公众号的白名单?


 回到顶部