URLDAY API 根据已发布的文档无法正常工作

问题描述 投票:0回答:1

我正在尝试使用 URLDAY 的 API 执行任何操作,但任何调用都会返回错误,无论它是来自 Python 代码还是来自 CURL。

示例:

curl --location \
    --request POST 'https://www.urlday.com/api/v1/links' \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --header 'Authorization: Bearer MYKEY' \
    --data-urlencode 'url=www.mysite.com'

并且得到


<!DOCTYPE html><html lang="en-US"><head><title>Just a moment...</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=Edge"><meta name="robots" content="noindex,nofollow"><meta name="viewport" content="width=device-width,initial-scale=1"><style>*{box-sizing:border-box;margin:0;padding:0}html{line-height:1.15;-webkit-text-size-adjust:100%;color:#313131;font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}body{display:flex;flex-direction:column;height:100vh;min-height:100vh}.main-content{margin:8rem auto;max-width:60rem;padding-left:1.5rem}@media (width <= 720px){.main-content{margin-top:4rem}}.h2{font-size:1.5rem;font-weight:500;line-height:2.25rem}@media (width <= 720px){.h2{font-size:1.25rem;line-height:1.5rem}}#challenge-error-text{background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI0IyMEYwMyIgZD0iTTE2IDNhMTMgMTMgMCAxIDAgMTMgMTNBMTMuMDE1IDEzLjAxNSAwIDAgMCAxNiAzbTAgMjRhMTEgMTEgMCAxIDEgMTEtMTEgMTEuMDEgMTEuMDEgMCAwIDEtMTEgMTEiLz48cGF0aCBmaWxsPSIjQjIwRjAzIiBkPSJNMTcuMDM4IDE4LjYxNUgxNC44N0wxNC41NjMgOS41aDIuNzgzem0tMS4wODQgMS40MjdxLjY2IDAgMS4wNTcuMzg4LjQwNy4zODkuNDA3Ljk5NCAwIC41OTYtLjQwNy45ODQtLjM5Ny4zOS0xLjA1Ny4zODktLjY1IDAtMS4wNTYtLjM4OS0uMzk4LS4zODktLjM5OC0uOTg0IDAtLjU5Ny4zOTgtLjk4NS40MDYtLjM5NyAxLjA1Ni0uMzk3Ii8+PC9zdmc+);background-repeat:no-repeat;background-size:contain;padding-left:34px}@media (prefers-color-scheme:dark){body{background-color:#222;color:#d9d9d9}}</style><meta http-equiv="refresh" content="390"></head><body class="no-js"><div class="main-wrapper" role="main"><div class="main-content"><noscript><div class="h2"><span id="challenge-error-text">Enable JavaScript and cookies to continue</span></div></noscript></div></div><script>(function(){window._cf_chl_opt={cvId: '3',cZone: "www.urlday.com",cType: 'managed',cRay: '8e08331dcca21acd',cH: 'HyW8MnqMqm6YWgrOmNPmohplrASP4fwSME_wvXU3lJU-1731264327-1.2.1.1-GiHFy7gK1YR1LgIRs9XsNTuIyhzpPt2ymtCIA81sVVAvQHst77aZKRq7k_TF6t8w',cUPMDTk: "\/api\/v1\/links?__cf_chl_tk=uY1iQn0S0a87ut2HpiKE.FZ4k_gLv8HwOxLHCt__Knw-1731264327-1.0.1.1-sg9FwzkoXlF75yOeYU7xDtEpVSKZkkHFqhu1y5V0Q1E",cFPWv: 'b',cITimeS: '1731264327',cTTimeMs: '1000',cMTimeMs: '390000',cTplC: 0,cTplV: 5,cTplB: 'cf',cK: "",fa: "\/api\/v1\/links?__cf_chl_f_tk=uY1iQn0S0a87ut2HpiKE.FZ4k_gLv8HwOxLHCt__Knw-1731264327-1.0.1.1-sg9FwzkoXlF75yOeYU7xDtEpVSKZkkHFqhu1y5V0Q1E",md: "KKYy.WDOpN3Nbh2hchr.5_65FIeP2MXY1SwLe7D0i9g-1731264327-1.2.1.1-8rDviJPWKQZ5GHZ2CJEs76rsOIWvKcleM6GXN_czTDntvOpBG15TYHn.r1BlH6CpuH.qNNZZLHgxeq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CAoqndPEtjsseTTLr4n47nLTdckWHjU7FcO0oQXRLj5n71Igq_NFwoJajXchLwP27Ao7hFuJw05QKSpL1KajV0KUkN8d072ALiql5JpeCyyIuYISy8TEIi_sjtC784cDkY3P4EM._sE3DGWQiIobSJGx9nq1.aWnAzZrbLNYlR4YM9XhkoW2B6tPbCfVyvo4m0d3.dg1BYgBjOTyV5UP1lF0"};var cpo = document.createElement('script');cpo.src = '/cdn-cgi/challenge-platform/h/b/orchestrate/chl_page/v1?ray=8e08331dcca21acd';window._cf_chl_opt.cOgUHash = location.hash === '' && location.href.indexOf('#') !== -1 ? '#' : location.hash;window._cf_chl_opt.cOgUQuery = location.search === '' && location.href.slice(0, location.href.length - window._cf_chl_opt.cOgUHash.length).indexOf('?') !== -1 ? '?' : location.search;if (window.history && window.history.replaceState) {var ogU = location.pathname + window._cf_chl_opt.cOgUQuery + window._cf_chl_opt.cOgUHash;history.replaceState(null, null, "\/api\/v1\/links?__cf_chl_rt_tk=uY1iQn0S0a87ut2HpiKE.FZ4k_gLv8HwOxLHCt__Knw-1731264327-1.0.1.1-sg9FwzkoXlF75yOeYU7xDtEpVSKZkkHFqhu1y5V0Q1E" + window._cf_chl_opt.cOgUHash);cpo.onload = function() {history.replaceState(null, null, ogU);}}document.getElementsByTagName('head')[0].appendChild(cpo);}());</script></body></html>

尝试使用Python:

url = "https://www.urlday.com/api/v1/links"
headers = {
    "Content-Type": "application/x-www-form-urlencoded",
    "Authorization": "Bearer eVnWvTBAD0Aai8w8YaAoopAgc3RZmRVEtmedYKNDZCIMg5Yv1Rbh7jTE77xf"
}
data = {
    "url": "www.mysite.com"
}

response = requests.post(url, headers=headers, data=data)

# Print the response
print("Status Code:", response.status_code)
print("Response JSON:", response.json())

获取

Exception has occurred: JSONDecodeError
Expecting value: line 1 column 1 (char 0)
StopIteration: 0

During handling of the above exception, another exception occurred:

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

  File "/home/noams/src/personal_website/backend/services/UrlShortener.py", line 55, in <module>
    print("Response JSON:", response.json())
                            ^^^^^^^^^^^^^^^
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

我尝试了一堆无用的解决方法,甚至不值得一提。


我显然错过了一些东西。访问他们的 API 的正确方法是什么?

python curl python-requests
1个回答
0
投票

您的目标应用程序受 Cloudflare 保护,因此您必须添加

user-agent
标头以及
cookie
(我不知道为什么他们没有在文档中提及它,而且
www.example.com
是无效的 URL 格式,你必须添加方案
http/https

如何找到你的cookie?:

Firefox --> 访问站点 -->

inspect element
-->
network
选项卡 -->
reload
--> 单击您的目标应用程序请求并从请求标头复制
cookie

User-Agent

做同样的事情

代码:

import requests

url = "https://www.urlday.com/api/v1/links"
headers = {
    "Content-Type": "application/x-www-form-urlencoded",
    "Authorization": "Bearer eVnWvTBAD0Aai8w8YaAoopAgc3RZmRVEtmedYKNDZCIMg5Yv1Rbh7jTE77xf",
    "Cookie": "YOUR COOKIE IS HERE", #add cookie value
    "User-Agent": "YOUR USER-AGENT HEADER IS HERE" #add user-agent header value
}
data = "url=https://www.example.com" #www.example.com is an invalid URL format, so add scheme too https/http

response = requests.post(url, headers=headers, data=data)

# Print the response
print("Status Code:", response.status_code)
print("Response JSON:", response.json())

输出:

Status Code: 201
Response JSON: {'data': {'id': 'peg2Pw3o', 'alias': 't7qza', 'url': 'https://www.example.com', 'short_url': 'https://urlday.cc/t7qza', 'title': 'Example Domain', 'target_type': None, 'country_target': None, 'platform_target': None, 'language_target': None, 'rotation_target': None, 'last_rotation': None, 'disabled': None, 'privacy': None, 'privacy_password': False, 'password': False, 'expiration_url': None, 'expiration_clicks': None, 'clicks': None, 'user_id': 5071, 'space': '', 'domain': None, 'pixels': '', 'ends_at': None, 'created_at': '2024-11-15T20:56:58.000000Z', 'updated_at': '2024-11-15T20:56:58.000000Z'}, 'status': 200}
© www.soinside.com 2019 - 2024. All rights reserved.