簡體   English   中英

如何突破OpenSea Api的限制?

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

我正在嘗試使用 OpenSea API,我注意到我需要在檢索資產之前設置一個限制https://docs.opensea.io/reference/getting-assets

我想我可以使用偏移量來瀏覽所有項目,即使這很乏味。 但問題是偏移量本身是有限制的,那么超出最大偏移量的資產是否無法訪問?

我讀到您說 API 在沒有 API 密鑰的情況下是“限速”的,所以我假設這與您在特定時間段內可以發出的請求數量有關,我對此是否正確? 還是放寬了歸還資產的限額? 文檔不清楚https://docs.opensea.io/reference/api-overview

我該怎么做才能瀏覽所有資產?

可能會遲到回答這個問題,但我遇到了類似的問題。 如果使用 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 是限速的,就像你說的。 因此,在出現討厭的 429 錯誤之前,您只能在一個時間范圍內對其 API 進行一定數量的調用。 因此,要么找到一種繞過速率限制的方法,要么在您的請求上設置一個計時器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM