Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 无法使用facebook graph api发送消息_Json_Django_Facebook Graph Api - Fatal编程技术网

Json 无法使用facebook graph api发送消息

Json 无法使用facebook graph api发送消息,json,django,facebook-graph-api,Json,Django,Facebook Graph Api,在我的django项目中 我有这个功能: def mesaj_yolla(): fbid="my_facebook_id" post_message_url = 'https://graph.facebook.com/v2.6/me/messages?access_token=<my_access_token>' response_msg = json.dumps({"recipient":{"id":fbid}, "message":{"text":"hel

在我的django项目中 我有这个功能:

def mesaj_yolla():
    fbid="my_facebook_id"
    post_message_url = 'https://graph.facebook.com/v2.6/me/messages?access_token=<my_access_token>'
    response_msg = json.dumps({"recipient":{"id":fbid}, "message":{"text":"hello"}})
    status = requests.post(post_message_url, headers={"Content-Type": "application/json"},data=response_msg)
    print(status)
def mesaj_yolla():
fbid=“我的facebook\u id”
发布消息https://graph.facebook.com/v2.6/me/messages?access_token='
response_msg=json.dumps({“recipient”:{“id”:fbid},“message”:{“text”:“hello”})
status=requests.post(post\u message\u url,headers={“Content Type”:“application/json”},data=response\u msg)
打印(状态)
它返回:

这些代码有什么问题?我只想向用户发送消息。

根据,您应该使用
收件人.id
而不是
收件人。用户id

def mesaj_yolla():
    fbid="my_facebook_id"
    post_message_url = 'https://graph.facebook.com/v2.6/me/messages?access_token=<my_access_token>'
    response_msg = json.dumps({"recipient":{"id":fbid}, "message":{"text":"hello"}})
    status = requests.post(post_message_url, headers={"Content-Type": "application/json"},data=response_msg)
    print(status)
def mesaj_yolla():
fbid=“我的facebook\u id”
发布消息https://graph.facebook.com/v2.6/me/messages?access_token='
response_msg=json.dumps({“recipient”:{“id”:fbid},“message”:{“text”:“hello”})
status=requests.post(post\u message\u url,headers={“Content Type”:“application/json”},data=response\u msg)
打印(状态)

这就是HTTP 400代码(错误请求)的原因。

对不起,我写错了,我忘了更改它。但是,它仍然无法工作。您无法在用户之间发送消息。这方面没有api。甚至没有一个/user/messages端点,不知道你从哪里得到这个想法?我在《我在facebook开发者上有一个应用程序》中尝试了第4节。messenger机器人用于页面和用户之间的通信,没有用于用户对用户通信的api。是的,我已经有了一个页面。你是否使用页面令牌?fbid是否为实际已开始使用机器人的用户的用户id?