【发布时间】:2021-12-24 10:48:34
【问题描述】:
我正在尝试通过 API GET 请求连接 Google 电子表格以从 snov.io 接收一些信息,但我得到的是 HTML 结果而不是 JSON。以下 Python 代码有效,但 Google Appscript 无效。有什么建议?谢谢你:)
Python 代码 - 工作
params = {
'access_token': token,
'domain': site,
'type': 'all',
'limit': 100,
'lastId': 0,
}
res = requests.get('https://api.snov.io/v2/domain-emails-with-info', params=params)
return json.loads(res.text)
AppScript - 不工作 - 收到 HTML 结果
'access_token': token,
'domain': site,
'type': 'all',
'limit': 100,
'lastId': 0,
}
var url = 'https://api.snov.io/v2/domain-emails-with-info'
var response = UrlFetchApp.fetch(url, {method: "get", payload: params, 'muteHttpExceptions': true});
var json = response.getContentText()
console.log(response.getContentText())
obj = JSON.parse(json)
result=obj.emails
return result
}
HTML 结果:(
<html>
<head>
<meta charset="UTF-8" />
<meta name="robots" content="noindex,nofollow" />
<style> body { background-color: #fff; color: #222; font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; margin: 0; }
.container { margin: 30px; max-width: 600px; }
h1 { color: #dc3545; font-size: 24px; }</style>
</head>
<body>
<div class="container">
<h1>Whoops, looks like something went wrong.</h1>
</div>
</body>
</html>
【问题讨论】:
标签: python html google-apps-script get google-apps-script-api