[原文網址](https://connect.spotware.com/docs/tutorials/lesson-2-get-trading-data)
我們的[上一課](https://connect.spotware.com/docs/tutorials/lesson-1-your-first-app)中的應用程序可以請求/ connect / shema之類的簡單請求,這些請求不需要身份驗證。 對于其他請求,需要身份驗證。 您必須為您在應用程序中使用的每個cTrader ID設置一個身份驗證令牌。 讓我們創建一個身份驗證令牌,并嘗試請求交易賬戶列表。
1. 如果要獲取cTrader ID的身份驗證令牌,則應運行中所述的操作[OAuth Services Description](https://connect.spotware.com/docs/api-reference/oauth-services-description)section of[API Reference](https://connect.spotware.com/docs/api-reference).
但是,為了測試我們的Open API,您可以使用[Playground](https://connect.spotware.com/docs/available-resources/playground)部分中描述的步驟。 我們將在沙盒連接站點注冊的測試應用程序“Test Partner”請求此身份驗證令牌。

1.首先單擊“發送帳戶API OAuth請求”鏈接。 您將看到一個請求令牌權限的頁面。

1.單擊“允許訪問”后,您將被重定向到Playground頁面,其中包含URL字符串中的短時間實時授權代碼。 您需要將此代碼交換為身份驗證令牌。 在10秒內,單擊Playground頁面上的“使用訪問令牌交換代碼”鏈接。 您的令牌將顯示在單獨的選項卡/窗口中,如:
~~~
{
"access_token":"OTA5Nzk3OTM3OTcwMDIxMmI0MTY1OTUxYTg4Mjg2NzQ4MGIzMzFmNjg3MTM1ZjVmZDQyYjBhNzQ5NjhkMzNjOA",
"expires_in":1209600,
"token_type":"bearer",
"scope":"accounts",
"refresh_token":"NTY0MGQ0NzExM2NmZjdjMWRiZjU3ODAxZjIwZDU1MGMxNGM0MjFiNWVjYWQyYWVlMjlhMTFkYzBkOGUyOTYzNA"
}
~~~
1.然后您可以打開[上一課的Java項目](https://connect.spotware.com/uploads/misc/Lesson1_Your_First_App.zip)并進行修改。 在我們的項目中,我們為Account API服務創建了一個包裝器,移動了URL請求它的方法,并根據[Accounts API Guide](https://connect.spotware.com/docs/api)添加了一個為請求構建字符串URL的方法-reference/帳戶-API)。 您應該通過上面請求的令牌替換文件** App.java **中的靜態字段** ACCOUNTS \ _API \ _TOKEN **。

Sources of this lesson you can find at[GitHub](https://github.com/spotware/connect-java-tutorials/tree/master/Lesson%202.%20Get%20Trading%20Data)
- 空白目錄
- API Reference 2.0
- Getting Started
- Open Authentication
- Protocol Buffers
- Protobuf Messages Reference
- Open API Messages
- Open API Model Messages
- Open API Error Codes
- Example Projects .NET
- Spotware Proxy Cloud
- Getting Started in C#
- Test Environment
- Playground
- Frequently Asked Questions
- Lesson 1. Your First App
- Lesson 2. Get Trading Data
- Lesson 3. Get Market Data
- Lesson 4. Using Trading API