高级接口--用户标签管理

Posted ahmay

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了高级接口--用户标签管理相关的知识,希望对你有一定的参考价值。

官方文档

官文中是标签管理。

创建标签:

def create_tag(access_token,name):
    # groups
    create_url = https://api.weixin.qq.com/cgi-bin/tags/create?access_token=%s% access_token
#
create_url = ‘https://api.weixin.qq.com/cgi-bin/tags/create?access_token=%s‘% access_token
# postData={‘group‘:{"name":name}}

postData ={ "tag" : { "name" : name } }
    response = requests.post(create_url,json.dumps(postData,ensure_ascii=False).encode(utf-8))
    return json.loads(response.text,encoding=utf-8)

获取公众号已创建的标签

def query_tags(access_token):
    query_url =https://api.weixin.qq.com/cgi-bin/tags/get?access_token=%s% access_token
    response = requests.get(query_url)
    return json.loads(response.text,encoding=utf-8

编辑标签

def update_tag(access_toke,postData):
    ‘‘‘{   "tag" : {     "id" : 134,     "name" : "广东人"   } } ‘‘‘
    update_url=https://api.weixin.qq.com/cgi-bin/tags/update?access_token=%s%access_token
    postData = json.dumps(postData,ensure_ascii=False).encode(utf-8)
    response = requests.post(update_url, postData)
    return json.loads(response.text,encoding=utf-8)

获取用户身上的标签列表

def query_usertags(access_token,openid):
    query_url=https://api.weixin.qq.com/cgi-bin/tags/getidlist?access_token=%s% access_token
    postData ={
        openid:openid
    }
    postData = json.dumps(postData, ensure_ascii=False).encode(utf-8)
    response = requests.post(query_url, postData)
    return json.loads(response.text,encoding=utf-8)

删除标签

def delete_tag(access_token,tag_id):
    delete_url =https://api.weixin.qq.com/cgi-bin/tags/delete?access_token=%s% access_token
    postData =json.dumps({"tag":{ "id" : tag_id } },ensure_ascii=False).encode(utf-8)
    response = requests.post(delete_url, postData)
    return json.loads(response.text, encoding=utf-8)

批量给用户列表打标签

def batch_packagetag(access_token,openids,tag_id):
    package_url =https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=%s% access_token
    postData ={
    "openid_list" :openids,
    "tagid" : tag_id
 }
    postData = json.dumps(postData)
    response = requests.post(package_url, postData)
    return json.loads(response.text, encoding=utf-8)

批量取消用户列表标签

def batch_untag(accesss_token,openids,tag_id):
    untag_url = https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token=%s % access_token
    postData = {
        "openid_list": openids,
        "tagid": tag_id
    }
    postData = json.dumps(postData)
    response = requests.post(untag_url, postData)
    return json.loads(response.text, encoding=utf-8)

 

获取标签下的粉丝列表:

def get_tag_fans(access_token,tag_id,next_openid=‘‘):
    #获取标签吓粉丝列表
    query_url =https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=%s% access_token
    params ={
        "tagid": tag_id, "next_openid": next_openid
    }
    response = requests.post(query_url,params)
    return json.loads(response.text,encoding=utf-8)
注意:这个函数有问题。没有任何用户的标签,竟然返回了用户。需要在正式公众号下面测试。另外文档说是GET,实际需要post

 

以上是关于高级接口--用户标签管理的主要内容,如果未能解决你的问题,请参考以下文章

高级接口--高级群发接口

Flask 编写http接口api及接口自动化测试

从父片段到选项卡片段的接口侦听器不起作用

推荐学java——MyBatis高级

推荐学java——MyBatis高级

推荐学java——MyBatis高级