获取OpenSea个人资料数据,使用Google Apps Script导入到Google Sheets。

huangapple go评论77阅读模式
英文:

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标志中找到链接:

获取OpenSea个人资料数据,使用Google Apps Script导入到Google Sheets。

然而,在运行时出现以下错误

异常:请求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 = &quot;https://opensea.io/0xe7dAe42Dee2BB6C1ef3c65e68d3E605faBcA875d&quot;;
  var response = UrlFetchApp.fetch(url).getContentText();
      
  var regex = /https:\/\/twitter.com\/[^&quot;&#39;]+/;
  var match = regex.exec(response);
  
  if (match &amp;&amp; match.length &gt; 0) {
    var twitterLink = match[0];
    Logger.log(&quot;Twitter Link: &quot; + twitterLink);
    return twitterLink;
  } else {
    Logger.log(&quot;Twitter Link not found.&quot;);
    return null;
  }
}

Here is the screenshot of the profile, you can find the link embedded in the Twitter logo on right most side:

获取OpenSea个人资料数据,使用Google Apps Script导入到Google Sheets。

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 = &quot;https://api.opensea.io/api/v1/user/0xe7dAe42Dee2BB6C1ef3c65e68d3E605faBcA875d&quot;;

 var options = {
    method: &#39;GET&#39;,
    headers: {
      &#39;X-API-KEY&#39;: &#39;YOUR_API_KEY&#39;
    },
    muteHttpExceptions: true
  };
  
 var response = UrlFetchApp.fetch(url, options);
 var payload = JSON.parse(response.getContentText());
 var twitterLink = &quot;https://twitter.com/&quot; + payload.account.twitter_username;
 console.log(twitterLink)
 }

Let me know if it helps.

huangapple
  • 本文由 发表于 2023年7月18日 13:59:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76709871.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定