【问题标题】:How to get over the limit of OpenSea Api?如何超越 OpenSea Api 的限制?
【发布时间】:2021-10-30 11:43:12
【问题描述】:

我正在尝试使用 OpenSea API,但我注意到我需要在检索资产之前设置一个限制 https://docs.opensea.io/reference/getting-assets

我想我可以使用偏移来浏览所有项目,尽管这很乏味。但是问题是offset本身是有限制的,那么超出maxoffset的资产是不是就无法访问了?

我读到您说 API 在没有 API 密钥的情况下是“速率限制”的,所以我假设这与您在特定时间段内可以发出的请求数量有关,我对此是否正确?还是取消了返还资产的限额?文档并不清楚https://docs.opensea.io/reference/api-overview

如何浏览所有资产?

【问题讨论】:

    标签: api rest blockchain nft opensea


    【解决方案1】:

    可能会迟到回答这个问题,但我遇到了类似的问题。如果使用 API,您只能访问有限数量 (50) 的资产。

    使用您链接到的页面上引用的 API,您可以执行 for 循环来获取范围内集合的资产。例如,使用 Python:

    import requests
    
    
    def get_asset(collection_address:str, asset_id:str) ->str: 
    
            url = "https://api.opensea.io/api/v1/assets?token_ids="+asset_id+"&asset_contract_address="+collection_address+"&order_direction=desc&offset=0&limit=20"
            response = requests.request("GET", url)
            asset_details = response.text
            return asset_details
        
        #using the Dogepound collection with address 0x73883743dd9894bd2d43e975465b50df8d3af3b2
        collection_address = '0x73883743dd9894bd2d43e975465b50df8d3af3b2'
        asset_ids = [i for i in range(10)]
        assets = [get_asset(collection_address, str(i)) for i in asset_ids]
        print(assets)
    

    对我来说,我实际上使用了 Typescript,因为这是 opensea 用于他们的 SDK (https://github.com/ProjectOpenSea/opensea-js) 的内容。它更加通用,允许您自动对资产进行报价、购买和销售。无论如何,这里是你如何在 Typescript 中获取所有这些资产的方法(你可能需要比下面引用的更多的依赖项):

        import * as Web3 from 'web3'
        import { OpenSeaPort, Network } from 'opensea-js'
        
        // This example provider won't let you make transactions, only read-only calls:
        const provider = new Web3.providers.HttpProvider('https://mainnet.infura.io')
        
        const seaport = new OpenSeaPort(provider, {
          networkName: Network.Main
        })
    
    
        async function getAssets(seaport: OpenSeaPort, collectionAddress: string, tokenIDRange:number) {
          let assets:Array<any> = []
          for (let i=0; i<tokenIDRange; i++) {
              try {
                let results = await client.api.getAsset({'collectionAddress':collectionAddress, 'tokenId': i,})
                assets = [...assets, results ]
              } catch (err) {
                console.log(err)
              }
              
          } 
      return Promise.all(assets)
    }
    
    
    (async () => {
      const seaport = connectToOpenSea();
      const assets = await getAssets(seaport, collectionAddress, 10);
      //Do something with assets 
     
    })();
    

    最后要注意的是,正如您所说,他们的 API 是速率受限的。因此,您只能在一个时间范围内对他们的 API 进行一定数量的调用,然后才会出现讨厌的 429 错误。因此,要么找到绕过速率限制的方法,要么为您的请求设置一个计时器。

    【讨论】:

      猜你喜欢
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-04
      相关资源
      最近更新 更多