我希望使用令牌(通过动态循环)提取所有JSON客户结果页。默认情况下,它只显示从第一页获得的结果。代码如附件所示。请建议一下。
# Request authorization via MainDB using Company ID
response = Excon.post(
"https://MainDB_APIEndpoint/#{Customer_Id}/login",
headers: { 'Authorization' => API_TOKEN }
)
# Get the login URL from the response
login_url = JSON.parse(response.body)['login_url']
# Make a request to the MainDB API for that tenant to auth with that tenant
response = Excon.get(login_url)
# Extract the cookies which will be used to auth future MainDB API requests for this tenant
cookies = response.data[:cookies].join('; ')
#Uses the cookie to make API calls to that customer
response = Excon.get(
"https://MainDB_APIEndpoint/sales/tickets",
headers: { 'Cookie' => cookies })
#Parses and returns result from the first page
page_data = JSON.parse(response.body)
csv = CSV.open('./output1_ticket.csv', 'w')
headers = nil
page_data['results'].each do |result|
if headers.nil?
headers = result.keys
csv << headers
end
csv << headers.map { |key| result[key] }
end
#Tried getting all the JSON pages but this doesn't seem to work
pages = Excon.get(
"https:/MainDB_APIEndpoint/sales/tickets/?page=5",
query: { page: page })发布于 2017-08-02 02:11:47
尝试使用以下语法:
connection = Excon.new('https:/MainDB_APIEndpoint/sales/tickets')
connection.get(query: { page: page })https://stackoverflow.com/questions/45271927
复制相似问题