我已经注册并根据Walgreens的用户ID提供了商店定位器API密钥的所有详细信息。
当我在python中运行下面的代码(使用相关的私有cred(时,我得到一个403代码,说affId丢失了。
以下是API文档中的示例代码,位于此处:https://developer.walgreens.com/sites/default/files/v1_StoreLocatorAPI.html#SearchZipcode
request POST
--url https://services-qa.walgreens.com/api/stores/search/v1
--header 'Content-Type: application/json'
--data '{
"apiKey":"YOUR_API_KEY",
"affId":"YOUR_AFFILIATE_ID",
"zip": CUSTOMER_ZIPCODE,
"r": RADIUS_MILES,
"filterOptions": FILTER_OPTIONS_ARRAY,
"requestType": "locator"
}
以下是我尝试创建一个对端点URL的调用,其中使用的相关参数减去API文档中的cred代码:
Python代码
import requests
#define variables
urlws = 'https://services-qa.walgreens.com/api/stores/search/v1'
waid = 'USERID'
wapikey = 'APIKEY'
waslid = 'storesapi'
wazip = '60000' #store zip code
war = '25' #radius of store in miles
rtype = 'locator'
#header 'Content-Type: application/json'
data = {'affId': waid,
'apiKey': wapikey,
'r': war,
'zip': wazip,
'requestType': rtype}
r = requests.get(urlws, params=data)
r
收到的响应{"errCode":"403","apiKey":","errMsg":"密钥不存在"}
你知道我做错了什么吗?
我是python和requests的新手。
TIA寻求任何帮助。
这是因为格式是JSON,必须使用post。一个例子。
import requests
response = requests.post('https://services-qa.walgreens.com/api/stores/search/v2', json={"apiKey":"Yourkey", "affId":"storesapi","address": "store address", "r":" 0", "s": "1", "requestType": "locator", "appVer":"1.0", "devInf":"DEVICE,##.#" })
print(response.url)
print(response.text)