API发布请求中检索会话密钥

API发布请求中检索会话密钥

本文介绍了如何从Skyscanner API发布请求中检索会话密钥-Ruby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我想通过此航班的详细信息获取实时价格,我已经使用过 SkyScanner API .在获得实时定价服务会话所需的数据之前,我已经阅读了文档.可以通过向api发送请求来创建,然后通过使用此SessionKeyapiKey提供SessionKey,我可以检索数据.因此,如我所知,如何获取Sessionkey必须由API Server提供.

In my app I want to fetch Live Price by Flight Details for this I have used SkyScanner API. I have read the documentation before obtained data I have to create Live Pricing Service Session. Which can be created by post request to api and then it provide SessionKey by using this SessionKey and apiKey I can retrived the data. So How can I get Sessionkey as I understood it must be provided by API Server.

这是我的尝试:

require 'json'
require 'net/http'
require 'uri'


  post_params = {
    :apiKey => "[API_KEY]",
    :country => "GB",
    :currency => "GBP",
    :locale => "en-GB",
    :adults =>1,
    :children => 0,
    :infants => 0,
    :originplace => '11235',
    :destinationplace => '13554',
    :outbounddate => '2015-05-19',
    :inbounddate => '2015-05-26',
    :locationschema => 'Default',
    :cabinclass => 'Economy',
    :groupPricing => true
  }


sessionkey_request = Net::HTTP.post_form(URI.parse('http://partners.api.skyscanner.net/apiservices/pricing/v1.0'), post_params )
get_data= "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/?apiKey=[API_KEY]"
puts sessionkey_request.inspect
temp = Net::HTTP.get_response(URI.parse(get_data)).body
# puts temp

在控制台中,我得到

<Net::HTTPCreated 201 Created readbody=true> # sessionkey_request.inspect

如果没有它,我没有得到 SessionKey ,我无法检索数据.请指导我我做错了的地方.感谢您提供解决方案.

Not getting SessionKey in response without it I can not retrieved data. Please guide me where I do mistake. I appreciate for solution.

更多详细信息和实时结果 检查演示 通过API

Fore more details and live result Check Demo by API

注意::我检查了 gem'skyscanner' ,但它不提供任何实时价格的方法.它提供了浏览缓存"方法.

Note: I have check gem 'skyscanner ' but it doesn't provide any method for Live Price. It provide Browse Cache methods.

推荐答案

根据文档:

所以尝试一下:

sessionkey_request["location"]

我已经在系统上对其进行了测试,并且返回了我:

I have test it on my system and it returns me:

http://partners.api.skyscanner.net/apiservices/pricing/v1.0/8e28260becd3441ca4e865396e224e7d_ecilpojl_EC71481935CEBB7EAF661BC24940D01D

最后一部分是您的sessionKey,您可以将其用于GET请求.如果只需要最后一部分(sessionKey),则可以通过以下方式检索它:

last part is your sessionKey which you can use for GET request. If you want only last part(sessionKey) then you can retrieved it by:

 > url = "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/8e28260becd3441ca4e865396e224e7d_ecilpojl_EC71481935CEBB7EAF661BC24940D01D"
 > url.split('/').last
 => "8e28260becd3441ca4e865396e224e7d_ecilpojl_EC71481935CEBB7EAF661BC24940D01D"

这篇关于如何从Skyscanner API发布请求中检索会话密钥-Ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-21 01:17