我正在尝试使用OpenSea API,我注意到在检索assets https://docs.opensea.io/reference/getting-assets之前需要设置一个限制。
我想我可以使用偏移量来浏览所有的项目,尽管这很繁琐。但是问题是偏移量本身是有限制的,所以超出最大偏移量的资产是不可访问的吗?
我读到你的API是“速率限制的”,没有API密钥,所以我假设这与你在某个时间段内可以发出的请求数量有关,我说的对吗?还是取消了返还资产的限制?文档中并没有明确介绍该https://docs.opensea.io/reference/api-overview
我可以做什么来浏览所有的资源?
发布于 2021-10-14 16:13:17
回答这个问题可能会晚一些,但我也有类似的问题。如果使用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 (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进行一定数量的调用。因此,要么找到一种绕过速率限制的方法,要么对您的请求设置一个计时器。
https://stackoverflow.com/questions/69005840
复制相似问题