英文:
Get OpenSea profile data using Google Apps Script into Google Sheets
问题
以下是已翻译的内容:
我正在尝试从OpenSea个人资料中获取Twitter链接,使用以下Google Apps Script示例代码:
function getTwitterLink() {
var url = "https://opensea.io/0xe7dAe42Dee2BB6C1ef3c65e68d3E605faBcA875d";
var response = UrlFetchApp.fetch(url).getContentText();
var regex = /https:\/\/twitter.com\/[^"']+/;
var match = regex.exec(response);
if (match && match.length > 0) {
var twitterLink = match[0];
Logger.log("Twitter Link: " + twitterLink);
return twitterLink;
} else {
Logger.log("Twitter Link not found.");
return null;
}
}
这是个人资料的截图,您可以在最右侧的Twitter标志中找到链接:
然而,在运行时出现以下错误:
异常:请求https://opensea.io返回代码403。
截断的服务器响应:<!DOCTYPE html> <html lang="en-US"> <head>
<title>Just a moment...</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-... (使用muteHttpExceptions选项来检查完整响应)
我认为这是因为我需要使用API密钥来获取这个Twitter链接。因此,我查看了OpenSea API文档。但无法找到任何相关的端点。如果您能指导我如何获取这个链接,我将不胜感激。谢谢。
英文:
I am trying to get Twitter link from OpenSea profile using the following Google Apps Script sample code:
function getTwitterLink() {
var url = "https://opensea.io/0xe7dAe42Dee2BB6C1ef3c65e68d3E605faBcA875d";
var response = UrlFetchApp.fetch(url).getContentText();
var regex = /https:\/\/twitter.com\/[^"']+/;
var match = regex.exec(response);
if (match && match.length > 0) {
var twitterLink = match[0];
Logger.log("Twitter Link: " + twitterLink);
return twitterLink;
} else {
Logger.log("Twitter Link not found.");
return null;
}
}
Here is the screenshot of the profile, you can find the link embedded in the Twitter logo on right most side:
However, it gives the following error when it runs:
> Exception: Request failed for https://opensea.io returned code 403.
> Truncated server response: <!DOCTYPE html> <html lang="en-US"> <head>
> <title>Just a moment...</title>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-... (use muteHttpExceptions option to examine full
> response)
I think this is because I need to use API key to get this Twitter link. So I reviewed OpenSea API Documentation. But unable to find any relevant endpoint. I would really appreciate it if you can guide me to get this. Thank you
答案1
得分: 0
以下是已翻译的内容:
当我查看文档时,我找到了获取Twitter账户信息的端点,所以这是提议的脚本:
function getTwitterLink() {
var url = "https://api.opensea.io/api/v1/user/0xe7dAe42Dee2BB6C1ef3c65e68d3E605faBcA875d";
var options = {
method: 'GET',
headers: {
'X-API-KEY': 'YOUR_API_KEY'
},
muteHttpExceptions: true
};
var response = UrlFetchApp.fetch(url, options);
var payload = JSON.parse(response.getContentText());
var twitterLink = "https://twitter.com/" + payload.account.twitter_username;
console.log(twitterLink)
}
让我知道是否有帮助。
英文:
When I looked at the documentation, I found the endpoint to get Twitter account information, so here is the proposed script:
function getTwitterLink() {
var url = "https://api.opensea.io/api/v1/user/0xe7dAe42Dee2BB6C1ef3c65e68d3E605faBcA875d";
var options = {
method: 'GET',
headers: {
'X-API-KEY': 'YOUR_API_KEY'
},
muteHttpExceptions: true
};
var response = UrlFetchApp.fetch(url, options);
var payload = JSON.parse(response.getContentText());
var twitterLink = "https://twitter.com/" + payload.account.twitter_username;
console.log(twitterLink)
}
Let me know if it helps.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论