It is the official text label management.
Create a label:
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')
Gets the label of public numbers that have been created
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'
Edit Labels
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')
Gets the label of a list of users who
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')
Remove label
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')
Batch tag the user list
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')
Batch cancel user list tags
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')
Fans get the list under the label:
DEF get_tag_fans (the access_token, tag_id, next_openid = '' ): # Get tag scare fan list query_url = ' https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=%s ' % the access_token the params = { " TagID " : tag_id, " next_openid " : next_openid } Response = requests.post (query_url, the params) return json.loads (response.text, encoding = ' UTF-. 8 ' )
Note: this function has a problem. Without any user's label, even returned to the user. We need to be tested in the following public official number. In addition the document said that the GET, the actual needs of post