Moh*_*ady 6 api rest blockchain nft opensea
我正在尝试使用 OpenSea API,我注意到我需要在检索资产之前设置限制 https://docs.opensea.io/reference/getting-assets
我想我可以使用偏移量来浏览所有项目,尽管这很乏味。但问题是offset本身是有限制的,超出最大offset的资产是不是就无法访问了呢?
我读到您说 API 在没有 API 密钥的情况下受到“速率限制”,所以我假设这与您在特定时间段内可以发出的请求数量有关,我的说法正确吗?还是解除了返还资产的限制?该文档不清楚https://docs.opensea.io/reference/api-overview
我可以做什么来浏览所有资产?
小智 5
可能迟到了回答这个问题,但我也遇到了类似的问题。如果使用 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)
Run Code Online (Sandbox Code Playgroud)
对我来说,我实际上使用了 Typescript,因为 opensea 在其 SDK 中使用的是 Typescript(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
})();
Run Code Online (Sandbox Code Playgroud)
最后要注意的是,正如您所说,他们的 API 是有速率限制的。因此,您只能在一段时间内对其 API 进行一定数量的调用,然后才会出现令人讨厌的 429 错误。因此,要么找到绕过速率限制的方法,要么为您的请求设置计时器。
| 归档时间: |
|
| 查看次数: |
9836 次 |
| 最近记录: |