在不设置测试用户账户的情况下,可以使用Facebook提供的测试工具和API来进行Messenger应用程序的审查流程。以下是一个解决方法的代码示例:
import requests
app_id = 'YOUR_APP_ID'
app_secret = 'YOUR_APP_SECRET'
# 创建测试应用程序
response = requests.post(
f'https://graph.facebook.com/{app_id}/test-users',
params={
'access_token': f'{app_id}|{app_secret}',
'installed': True,
'permissions': 'publish_actions'
}
)
test_user = response.json()
# 获取测试用户的访问令牌
test_user_access_token = test_user['access_token']
# 发送消息给测试用户
response = requests.post(
f'https://graph.facebook.com/me/messages',
params={
'access_token': test_user_access_token
},
json={
'recipient': {'id': 'YOUR_PAGE_ID'},
'message': {'text': 'Hello, this is a test message!'}
}
)
# 获取测试用户的收件箱
response = requests.get(
f'https://graph.facebook.com/me/inbox',
params={
'access_token': test_user_access_token
}
)
inbox = response.json()
# 验证消息是否发送成功
for thread in inbox['data']:
if thread['to']['data'][0]['id'] == 'YOUR_PAGE_ID' and thread['messages']['data'][0]['message'] == 'Hello, this is a test message!':
print('Message sent successfully!')
break
请注意,上述代码示例仅演示了如何使用Graph API来进行Messenger应用程序的审查流程,并不包含完整的错误处理和其他功能。在实际应用中,您可能需要根据具体需求进行修改和完善。