我正在尝试获取在opensea.io上销售的商品的报价列表。
def getHighestOffer(self):
query = """query OrdersQuery(\n $cursor: String\n $count: Int = 10\n $excludeMaker: IdentityInputType\n $isExpired: Boolean\n $isFilled: Boolean\n $isValid: Boolean\n $maker: IdentityInputType\n $makerArchetype: ArchetypeInputType\n $makerAssetIsPayment: Boolean\n $takerArchetype: ArchetypeInputType\n $takerAssetCategories: [CollectionSlug!]\n $takerAssetCollections: [CollectionSlug!]\n $takerAssetIsOwnedBy: IdentityInputType\n $takerAssetIsPayment: Boolean\n $sortAscending: Boolean\n $sortBy: OrderSortOption\n $makerAssetBundle: BundleSlug\n $takerAssetBundle: BundleSlug\n) {\n ...Orders_data_2g7x2d\n}\n\nfragment AccountLink_data on AccountType {\n address\n chain {\n identifier\n id\n }\n user {\n publicUsername\n id\n }\n ...ProfileImage_data\n ...wallet_accountKey\n}\n\nfragment AskPrice_data on OrderV2Type {\n dutchAuctionFinalPrice\n openedAt\n priceFnEndedAt\n makerAssetBundle {\n assetQuantities(first: 30) {\n edges {\n node {\n ...quantity_data\n id\n }\n }\n }\n id\n }\n takerAssetBundle {\n assetQuantities(first: 1) {\n edges {\n node {\n ...AssetQuantity_data\n id\n }\n }\n }\n id\n }\n}\n\nfragment AssetCell_assetBundle on AssetBundleType {\n assetQuantities(first: 2) {\n edges {\n node {\n asset {\n collection {\n name\n id\n }\n name\n ...AssetMedia_asset\n ...asset_url\n id\n }\n relayId\n id\n }\n }\n }\n name\n slug\n}\n\nfragment AssetMedia_asset on AssetType {\n animationUrl\n backgroundColor\n collection {\n description\n displayData {\n cardDisplayStyle\n }\n imageUrl\n hidden\n name\n slug\n id\n }\n description\n name\n tokenId\n imageUrl\n}\n\nfragment AssetQuantity_data on AssetQuantityType {\n asset {\n ...Price_data\n id\n }\n quantity\n}\n\nfragment Orders_data_2g7x2d on Query {\n orders(after: $cursor, excludeMaker: $excludeMaker, first: $count, isExpired: $isExpired, isFilled: $isFilled, isValid: $isValid, maker: $maker, makerArchetype: $makerArchetype, makerAssetIsPayment: $makerAssetIsPayment, takerArchetype: $takerArchetype, takerAssetCategories: $takerAssetCategories, takerAssetCollections: $takerAssetCollections, takerAssetIsOwnedBy: $takerAssetIsOwnedBy, takerAssetIsPayment: $takerAssetIsPayment, sortAscending: $sortAscending, sortBy: $sortBy, makerAssetBundle: $makerAssetBundle, takerAssetBundle: $takerAssetBundle) {\n edges {\n node {\n closedAt\n isFulfillable\n isValid\n oldOrder\n openedAt\n orderType\n maker {\n address\n ...AccountLink_data\n ...wallet_accountKey\n id\n }\n makerAsset: makerAssetBundle {\n assetQuantities(first: 1) {\n edges {\n node {\n asset {\n assetContract {\n account {\n address\n chain {\n identifier\n id\n }\n id\n }\n id\n }\n id\n }\n id\n }\n }\n }\n id\n }\n makerAssetBundle {\n assetQuantities(first: 30) {\n edges {\n node {\n ...AssetQuantity_data\n ...quantity_data\n id\n }\n }\n }\n id\n }\n relayId\n side\n taker {\n ...AccountLink_data\n ...wallet_accountKey\n id\n address\n }\n takerAssetBundle {\n assetQuantities(first: 1) {\n edges {\n node {\n ...AssetQuantity_data\n ...quantity_data\n asset {\n ownedQuantity(identity: {})\n decimals\n symbol\n relayId\n assetContract {\n account {\n address\n id\n }\n id\n }\n id\n }\n quantity\n id\n }\n }\n }\n id\n }\n ...AskPrice_data\n ...orderLink_data\n makerAssetBundleDisplay: makerAssetBundle {\n ...AssetCell_assetBundle\n id\n }\n takerAssetBundleDisplay: takerAssetBundle {\n ...AssetCell_assetBundle\n id\n }\n id\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }\n}\n\nfragment Price_data on AssetType {\n decimals\n imageUrl\n symbol\n usdSpotPrice\n assetContract {\n blockExplorerLink\n id\n }\n}\n\nfragment ProfileImage_data on AccountType {\n imageUrl\n address\n chain {\n identifier\n id\n }\n}\n\nfragment asset_url on AssetType {\n assetContract {\n account {\n address\n chain {\n identifier\n id\n }\n id\n }\n id\n }\n tokenId\n}\n\nfragment orderLink_data on OrderV2Type {\n makerAssetBundle {\n assetQuantities(first: 30) {\n edges {\n node {\n asset {\n externalLink\n collection {\n externalUrl\n id\n }\n id\n }\n id\n }\n }\n }\n id\n }\n}\n\nfragment quantity_data on AssetQuantityType {\n asset {\n decimals\n id\n }\n quantity\n}\n\nfragment wallet_accountKey on AccountType {\n address\n chain {\n identifier\n id\n }\n}\n"""
variables = {"cursor":None,"count":10,"excludeMaker":None,"isExpired":False,"isFilled":None,"isValid":True,"maker":None,"makerArchetype":None,"makerAssetIsPayment":True,"takerArchetype":{"assetContractAddress":"0x7c40c393dc0f283f318791d746d894ddd3693572","tokenId":"7722"},"takerAssetCategories":None,"takerAssetCollections":None,"takerAssetIsOwnedBy":None,"takerAssetIsPayment":None,"sortAscending":None,"sortBy":"MAKER_ASSETS_USD_PRICE","makerAssetBundle":None,"takerAssetBundle":None}
response = requests.post('https://api.opensea.io/graphql/', json={'query': query},data=variables)
print(response.text)
在变量中,“assetContractAddress”和“tokenId”是该项目所特有的。
但是我运行时出现了以下问题:
{"errors":[{"message":"必须提供查询字符串。"}]}
如果我在 requests.post
中不使用data = variables
,则会得到:
{"errors":[{"message":"[400] taker_asset_categories、taker_asset_collections、maker、taker、maker、include_maker_assets、include_taker_assets、maker_assets、taker_assets、maker_asset_is_owned_by、taker_asset_is_owned_by、exclude_maker、maker_asset_bundle、taker_asset_bundle 中的一个需要被定义。","locations":[{"line":118,"column":3}],"path":["orders"]}],"data":{"orders":null}}
我该如何使用查询和变量来正确获取响应?
谢谢!
requests.post()
中,您应该提供data
或json
,但不要同时提供两者。