简体   繁体   English

从 Python 中的 REST API 迁移 Mintegral 数据

[英]Mintegral Data Migration from REST API in Python

Mintegral REST API document https://www.mintegral.com/wp-content/uploads/2018/10/1-Mintegral_Reporting-API.pdf Mintegral REST API document https://www.mintegral.com/wp-content/uploads/2018/10/1-Mintegral_Reporting-API.pdf

When I run this code in Python, it always returns {"code":400,"msg":"Validation fails (Token Error)","data":null} (screenshot attached)当我在 Python 中运行此代码时,它总是返回{"code":400,"msg":"Validation fails (Token Error)","data":null} (附截图) 在此处输入图像描述

The API key and username are correct. API 密钥和用户名正确。 I don't know why????不知道为什么????

import requests
import time
import hashlib 

apikey = "xxxx"
encoded_timestamp = hashlib.md5(str(time.time()).encode())
token = apikey + encoded_timestamp.hexdigest()
md5_token = hashlib.md5(token.encode()).hexdigest()

response = requests.get("http://data.mintegral.com/v4.php?m=advertiser",
                        params = {
                        'username':'XXXABC'
                        ,'token':md5_token
                        ,'timestamp':str(int(time.time()))
                        # ,'utc':'+8'
                ,'start_date':'2022-06-07'
                ,'end_date':'2022-06-13'
                ,'Content-type': 'application/json'
                # ,'per_page':5000
                }
                )
response.text

But when I checked the example in PHP, it works.但是当我检查 PHP 中的示例时,它可以工作。 Could you please help me to fix the Python code?您能帮我修复 Python 代码吗? 在此处输入图像描述 Anyone has experience about it?有人有这方面的经验吗?

Thanks much in advance!提前非常感谢!

Looks like, you forget to make str(int(time.time())) in 6-th line看起来,您忘记在第 6 行创建 str(int(time.time()))

Btw, the problem is in logic.顺便说一句,问题出在逻辑上。 You use the time.time() function twice, once when creating token and second time while POST.您使用 time.time() function 两次,一次是在创建令牌时,第二次是在 POST 时。 Because of this, your hash is different from server hash.因此,您的 hash 与服务器 hash 不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM