以下是两种
python发表
微信公众号的例子:
1. 获取
微信公众号AccessToken
```
python
# 以服务号为例
i
mport requests
appid =
'your_appid
'
appsecret =
'your_appsecret
'
url = f
'https://api.
weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={appid}&secret={appsecret}
'
respo
nse = requests.get(url)
access_token = response.json()[
'access_token
']
print("Access Token:", access_token)
```
2. 上传
微信公众号首图
```
python
# 上传图片
i
mport requests
url = "https://api.
weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=image"
files = {
'media
': open(
'example.jpg
',
'rb
')}
respo
nse = requests.post(url, files=files)
media_id = response.json()[
'media_id
']
print("Media ID:", media_id)