VFP 愛用者社區 首頁 VFP 愛用者社區
本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
 
 常見問題常見問題   搜尋搜尋   會員列表會員列表   會員群組會員群組   會員註冊會員註冊 
 個人資料個人資料   登入檢查您的私人訊息登入檢查您的私人訊息   登入登入

呼叫 API 出錯

 
發表新主題   回覆主題    VFP 愛用者社區 首頁 -> VFP 討論區
上一篇主題 :: 下一篇主題  
發表人 內容
foxy



註冊時間: 2007-08-16
文章: 231
來自: 泰國

第 1 樓

發表發表於: 星期二 七月 11, 2023 2:42 pm    文章主題: 呼叫 API 出錯 引言回覆

各位先進,
你好
小弟需要從 VFP 呼叫一個網頁,以便得到 token 才能繼續資料傳輸.
根據該網頁要求, 格式如下

An example request message for access token in curl command format

curl --location --request POST '/https://openapi-sandbox.kasikornbank.com/oauth/token'
--header 'Content-Type: application/x-www-form-urlencoded'
--header 'Authorization: Basic NmxzMHB6M0NVUE1ORG10RzlHNUI2WFU4MzJETnBHTGc6VUZpSHZpWmRzRzF1aThKNw=='
--data-urlencode 'grant_type=client_credentials'

小弟在 vfp 使用如下指令, 但是不能成功
<vfp>
m.lcurl='https://openapi-sandbox.kasikornbank.com/oauth/token'
m.lcidkey='NmxzMHB6M0NVUE1ORG10RzlHNUI2WFU4MzJETnBHTGc6VUZpSHZpWmRzRzF1aThKNw=='
xmlHTTP = createobject("msxml2.xmlhttp")
xmlHTTP.Open("POST", m.lcUrl, .F.)
xmlHTTP.setRequestHeader("Authorization", "Basic"+space(1)+m.lcidkey)

xmlHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
xmlHTTP.setRequestHeader("env-id", "OAUTH2")
xmlHTTP.setRequestHeader("x-test-mode", "true")
m.lcbody= "grant_type=client_credentials"
xmlHTTP.Send(m.lcbody)
</vfp>
API 網頁傳回的錯誤訊息如下
{
"code": "openapi_error",
"message": "Invalid ApiKey for given resource"
}

似乎是 https 需要 正確的 certificate, 該如何處理?



下面是該網頁需要的格式

Instructions

Read the exercise details below carefully.
Call an API with the applicable parameters from the table. You are able to call an API by 2 methods:
Add the request parameter in the Headers and Body box and click “Execute” button
Call API from your server or other program e.g. Postman
URL: https://openapi-sandbox.kasikornbank.com/oauth/token
*you have to add Header "x-test-mode" : "true"
*you have to add Header "env-id" : "OAUTH2"
Check the return message from API and check your results.
Exercise: Authenticate with OAuth Client Credentials

OAuth Information
Header
Authorization Your credentials.
Content-Type application/x-www-form-urlencoded
Body
grant_type client_credentials
Credentials

Consumer ID suDxvMLTLYsQwL1R0L9UL1m8Ceoibmcr
Consumer Secret goOfPtGLoGxYP3DG


How to do OAuth 2.0 to get access token

1. Click on the menu Get Credential on the left hand side or go to "My Apps" Menu and click "App Detail" Menu then the system displays your Consumer ID, Consumer Secret with the screen below.



Consumer ID = suDxvMLTLYsQwL1R0L9UL1m8Ceoibmcr
Consumer Secret = goOfPtGLoGxYP3DG


2. Generate a Basic Authentication format with your Consumer ID and Consumer Secret with the step below


Combined the dataset to the format <Consumer ID>:<Consumer Secret>
From the example, the data set is
a2FzaWtvcm5iYW5rdXNlcg==:a2FzaWtvcm5iYW5rcGFzc3dvcmQ=

Encode the dataset in Base64 encoded format.
From the example, the data set is
YTJGemFXdHZjbTVpWVc1cmRYTmxjZz09OmEyRnphV3R2Y201aVlXNXJjR0Z6YzNkdmNtUT0=

Take the encrypted data set to place in the header section according to the following format:
Authorization : Basic <encrypted dataset>
From the example, the data set is

Authorization : Basic YTJGemFXdHZjbTVpWVc1cmRYTmxjZz09OmEyRnphV3R2Y201aVlXNXJjR0Z6YzNkdmNtUT0=

3 .Specify in the header as Content-Type: application/x-www-form-urlencoded

4. Specify in the body as grant_type=client_credentials.

5. The access token will be used to continue making other API calls with a validity of 30 minutes.



An example request message for access token in curl command format

curl --location --request POST 'https://example.kasikornbank.com/oauth/token'
--header 'Content-Type: application/x-www-form-urlencoded'
--header 'Authorization: Basic YTJGemFXdHZjbTVpWVc1cmRYTmxjZz09OmEyRnphV3R2Y201aVlXNXJjR0Z6YzNkdmNtUT0='
--data-urlencode 'grant_type=client_credentials'



謝謝

_________________
進銷存+生產製造+會計+員工薪資+CRM+POS零售+餐廳手機app+電商手機app+電商網站,物流系統. 正/簡體中文,英,日,泰,緬甸文. MS SQL Server + 前台 VFP + PHP 網站 + Flutter 手機 App, 都共享 MS SQL Server的資料. www.foxacc.com LINE: mike-lm
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件 參觀發表人的個人網站 MSN Messenger
從之前的文章開始顯示:   
發表新主題   回覆主題    VFP 愛用者社區 首頁 -> VFP 討論區 所有的時間均為 台北時間 (GMT + 8 小時)
1頁(共1頁)

 
前往:  
無法 在這個版面發表文章
無法 在這個版面回覆文章
無法 在這個版面編輯文章
無法 在這個版面刪除文章
無法 在這個版面進行投票
無法 在這個版面附加檔案
無法 在這個版面下載檔案


Powered by phpBB © 2001, 2005 phpBB Group
正體中文語系由 phpbb-tw 維護製作