Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.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
Python 向API AI发送位置(横向和纵向)_Python_Json_Facebook - Fatal编程技术网

Python 向API AI发送位置(横向和纵向)

Python 向API AI发送位置(横向和纵向),python,json,facebook,Python,Json,Facebook,我正在用它制作一个Facebook机器人。在Facebook聊天机器人中分享我的位置后。我得到了这样一个JSON: {'message': {'attachments': [{'payload': {'coordinates': {'lat': 52.335001190772,'long': 4.8887078680234}},'title': 'Holiday Inn','type': 'location','url': 'https://www.facebook.com/l.php?u=ht

我正在用它制作一个Facebook机器人。在Facebook聊天机器人中分享我的位置后。我得到了这样一个JSON:

{'message': {'attachments': [{'payload': {'coordinates': {'lat': 52.335001190772,'long': 4.8887078680234}},'title': 'Holiday Inn','type': 'location','url': 'https://www.facebook.com/l.php?u=https%3A%2F%2Fwww.bing.com%2Fmaps%2Fdefault.aspx%3Fv%3D2%26pc%3DFACEBK%26mid%3D8100%26where1%3DDe%2BBoelelaan%2B2%252C%2B1083%2BHJ%2BAmsterdam%252C%2BNetherlands%26FORM%3DFBKPL1%26mkt%3Den-US&h=mAQEt4NIX&s=1&enc=AZN97DQxpVq5xpkZqvgi3bMq2OVJNwWBOXOiIOW4FHx1-kgYHxTPKfFwRkUsl0ibr0K5GAquaEltxBMLGvjxmUbCa1AmptlN85rg4jLhDH6K0g'}],
根据该JSON,我有lat和long值:

payload = message['message']['attachments'][0]['payload']
lat = payload['coordinates']['lat']
long = payload['coordinates']['long']
我想要的是将这些值发送到API AI中的
参数。所以我写了一个方法来发布:

def post_location(self, text, lat, long):
    return self.get(
        params={
            'query': text,
            'parameters': {
                    'latitude': lat,
                    'longitude': long,
            },
            'lang': 'en'
        }
    )
这就是我的
get
的样子:

def get(self, params):
    """
    Get connection with api ai
    :rtype: object
    """
    print(params)

    request = requests.get(
        url=self.url, params=params, headers=self.headers)
    content = request.content.decode('utf-8')
    try:
        return json.loads(content)
    except ValueError:
        print('Invalid JSON')
最后,我调用
post_location
方法,在这里我处理facebook消息并给它赋值,但当我运行时,只有
文本
(查询)被发送到API AI

def _post_location_to_api(message, lat, long):
    ai_api = AIApi()
    return ai_api.post_location(message, lat, long)

location = _post_location_to_api(message['message']['attachments'][0]['type'], latitude, longitude)
print(location)
告诉我:

{'id': 'd4374511-86ce-4ccb-b7b3-e813011a0998', 'sessionId': '00000000-0000-0000-0000-000000000000', 'timestamp': '2016-10-04T11:26:11.613Z', 'result': {'action': 'PlaceSearch', 'actionIncomplete': False, 'score': 0.51, 'contexts': [], 'fulfillment': {'speech': ''}, 'parameters': {'latitude': '', 'longitude': ''}, 'source': 'agent', 'resolvedQuery': 'location', 'metadata': {'intentName': 'I want to eat in Amsterdam', 'intentId': '89f515a6-f723-4df5-96b2-9e0f784747c6', 'webhookUsed': 'true', 'warning': 'IMPORTANT: Please use unique session ID for each client. Otherwise you may experience unstable behaviour.'}}, 'status': {'errorDetails': 'Webhook call failed. Status code 404. Error:404 Not Found', 'errorType': 'partial_content', 'code': 206}}
我做错了什么