我可以通过以下代码在生产环境中生成access_token
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.amadeus.com/v1/security/oauth2/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "client_id=XXX&client_secret=XXX&grant_type=client_credentials",
CURLOPT_HTTPHEADER => array(
// Set here requred headers
"accept: */*",
"accept-language: en-US,en;q=0.8",
"content-type: application/x-www-form-urlencoded",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
之后,我尝试致电
https://api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=MUC
API。通过使用以下代码
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.amadeus.com/v1/shopping/flight-dates?origin=JFK&destination=LHR&oneWay=false&nonStop=false",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
// Set here requred headers
"accept: */*",
"accept-language: en-US,en;q=0.8",
"content-type: application/x-www-form-urlencoded",
"Authorization: Bearer XXX",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
我遇到以下错误
{
"errors": [
{
"status": 401,
"title": "Wrong authentication credentials.",
"code": 701,
"source": {
"pointer": "shopping/flight-dates"
}
}
]
}
我在做错什么。
答案 0 :(得分:1)
我们遇到了一个内部配置问题,该问题已得到解决,现在一切正常。
2件事: 此API不支持机场代码,您需要将其替换为城市代码(LHR-> LON / JFK-> NYC),这也是我们积压的一部分,也支持机场代码,但尚未交付。因此,API调用应为:
唯一需要的标头是:
def initUI(self):
self.close_pushbtn = QtGui.QPushButton(
text="Close",
sizePolicy=QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Maximum)
)
self.line = QtGui.QFrame(frameShape=QtGui.QFrame.HLine)
self.add_btn = QtGui.QPushButton(
text="Add",
sizePolicy=QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Maximum)
)
label = QtGui.QLabel(text="address ")
le = QtGui.QLabel(text="scroll area")
title_hbox = QtGui.QHBoxLayout()
title_hbox.addWidget(self.close_pushbtn, alignment=QtCore.Qt.AlignRight)
order_hbox = QtGui.QHBoxLayout()
order_hbox.addWidget(label)
order_hbox.addWidget(le)
addhbox = QtGui.QHBoxLayout()
addhbox.addWidget(self.add_btn, alignment=QtCore.Qt.AlignCenter)
grid = QtGui.QVBoxLayout(self)
grid.addLayout(title_hbox)
grid.addWidget(self.line)
grid.addLayout(order_hbox)
grid.addLayout(addhbox)
self.resize(800, 300)
self.show()