希望这是一个简单的问题,谢谢你的帮助。
我的目标:从Hubspot工作流发送一些数据到Meta/Facebook的转换API。
我的问题:当我尝试发送数据时,我收到以下错误:
{"error":{"message":"(#100) The parameter data is required","type":"OAuthException","code":100,"fbtrace_id":"AajsbCdtXpN5mhcKQaTylmC"}}
我的代码:
url = f'https://graph.facebook.com/v13.0/data_ommitted/events?access_token={facebookkey}&test_event_code=TEST79983'
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
myData = {
"action_source" : "website",
"event_name" : "Lead",
"event_time" : unix_timestamp,
"user_data": {
"em": [email],
"fn": [firstname],
"ln": [lastname],
"zp": [zipcode],
}
}
print(myData)
try:
x = requests.post(url, data=myData, headers=headers)
print(x.text)
except Exception as e:
print(e)
finally:
print('Succesfully sent.')
我试过了:我尝试了以下方法,这让我离目标更近了一点:
x = requests.post(url, data={"data": [myData]}, headers=headers)
print(x.text)
{"error":{"message":"(#100) param data must be an array."
示例数据:
print(myData)
{'action_source': 'website', 'event_name': 'Lead', 'event_time': 1652901832, 'user_data': {'em': ['7c288df52b285801c4fe184d257d4ba521ece9dc2d74fddef21fde5b763fa693'], 'fn': ['9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'], 'ln': ['9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'], 'zp': ['dc937b59892604f5a86ac96936cd7ff09e25f18ae6b758e8014a24c7fa039e91']}}
Facebook期望:
{
"data": [
{
"event_name": "Lead",
"event_time": 1652898537,
"action_source": "website",
"user_data": {
"em": [
"7c288df52b285801c4fe184d257d4ba521ece9dc2d74fddef21fde5b763fa693"
],
"zp": [
"dc937b59892604f5a86ac96936cd7ff09e25f18ae6b758e8014a24c7fa039e91"
],
"fn": [
"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
],
"ln": [
"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
]
}
}
]
}
谢谢你的帮助!
我明白了!:)这是你需要发送的内容:
x = requests.post(url, data=json.dumps({"data":[myData]}), headers=headers)