简体   繁体   English

如何突破OpenSea Api的限制?

[英]How to get over the limit of OpenSea Api?

I am trying to use OpenSea API and I noticed that I need to set a limit before retrieving assets https://docs.opensea.io/reference/getting-assets我正在尝试使用 OpenSea API,我注意到我需要在检索资产之前设置一个限制https://docs.opensea.io/reference/getting-assets

I figured I can use the offset to navigate through all the items, even though that's tedious.我想我可以使用偏移量来浏览所有项目,即使这很乏味。 But the problem is offset itself has a limit, so are assets beyond the max offset inaccessible ?但问题是偏移量本身是有限制的,那么超出最大偏移量的资产是否无法访问?

I read that you that the API is "rate-limited" without an API key, so I assume that related to the number of requests you can make in a certain time period, am I correct about that?我读到您说 API 在没有 API 密钥的情况下是“限速”的,所以我假设这与您在特定时间段内可以发出的请求数量有关,我对此是否正确? Or does it lift the limit of returned assets ?还是放宽了归还资产的限额? The documentation isn't clear about that https://docs.opensea.io/reference/api-overview文档不清楚https://docs.opensea.io/reference/api-overview

What can I do to navigate through all the assets ?我该怎么做才能浏览所有资产?

May be late answering this one, but I had a similar problem.可能会迟到回答这个问题,但我遇到了类似的问题。 You can only access a limited number (50) assets if using the API.如果使用 API,您只能访问有限数量 (50) 的资产。

Using the API referenced on the page you linked to, you could do a for loop to grab assets of a collection in a range.使用您链接到的页面上引用的 API,您可以执行 for 循环来获取某个范围内集合的资产。 For example, using Python:例如,使用 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)

For me, I actually used Typescript because that's what opensea use for their SDK ( https://github.com/ProjectOpenSea/opensea-js ).对我来说,我实际上使用了 Typescript,因为 opensea 使用的是他们的 SDK ( https://github.com/ProjectOpenSea/opensea-js )。 It's a bit more versatile and allows you to automate making offers, purchases and sales on assets.它的用途更广,允许您自动对资产进行报价、购买和销售。 Anyway here's how you can get all of those assets in Typescript (you may need a few more dependencies than those referenced below):无论如何,这里是您如何在 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 
 
})();

The final thing to be aware of is that their API is rate limited, like you said.最后要注意的是,他们的 API 是限速的,就像你说的。 So you can only make a certain number of calls to their API within a time frame before you get a pesky 429 error.因此,在出现讨厌的 429 错误之前,您只能在一个时间范围内对其 API 进行一定数量的调用。 So either find a way of bypassing rate limits or put a timer on your requests.因此,要么找到一种绕过速率限制的方法,要么在您的请求上设置一个计时器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM