# Todoist API
使用Todoist API和VBA-Web的示例包含在項目的`examples / todoist`文件夾中。 一些細節:
## [](https://github.com/VBA-tools/VBA-Web/wiki/Todoist-API#authentication)Authentication授權
Todoist [API文檔](https://developer.todoist.com/)描述了如何對Todoist API進行身份驗證和請求。 根據[授權:OAuth](https://developer.todoist.com/#oauth)部分,需要以下項目:客戶端ID,客戶端密鑰和重定向URL。這些可以在[Todoist App Management Console](https://developer.todoist.com/appconsole.html)中找到。 對于重定向網址,任何有效網址似乎都有效,因為只有查詢字符串用于身份驗證(例如[www.example.com](http://www.example.com/),[www.yourcompany.com](http://www.yourcompany.com/)等)
1. 轉到[https://developer.todoist.com/appconsole.html](https://developer.todoist.com/appconsole.html),根據需要創建一個新應用程序,并記下客戶端ID和客戶端密鑰
2. 為您的應用設置重定向網址(請參閱上面的注釋)
3. 從[https://developer.todoist.com/#oauth](https://developer.todoist.com/#oauth)確定應用程序的范圍(例如`data:read,task:add`)
4. 將`TodoistAuthenticator`添加到您的項目中并按如下方式進行設置
~~~vbnet
Dim Auth As New TodoistAuthenticator
Auth.Setup _
ClientId:="Your Client Id", _
ClientSecret:="Your Client Secret"
RedirectUrl:="Your Redirect Url"
Auth.Scope = "data:read,task:add"
Set Client.Authenticator = Auth
~~~
## [](https://github.com/VBA-tools/VBA-Web/wiki/Todoist-API#example-request)Example Request請求范例
通過客戶端的身份驗證設置,您可以使用正常的請求配置。 以下是檢索您擁有的項目列表以及如何設置請求的所需URL的示例:(請參閱[https://developer.todoist.com/#retrieve-data](https://developer.todoist.com))
~~~vbnet
'// 期望的請求: POST https://todoist.com/API/v6/sync
'// ?token=SET Automatically from TodoistAuthenticator
'// &seq_no=0
'// &seq_no_global=0
'// &resource_types=["projects"]
Public Function CountProjects() As Long
Dim Client As New WebClient
Client.BaseUrl = "https://todoist.com/API/v6"
Dim Auth As New TodoistAuthenticator
Auth.Setup _
ClientId:="Your Client Id", _
ClientSecret:="Your Client Secret"
RedirectUrl:="Your Redirect Url"
Auth.Scope = "data:read,task:add"
Set Client.Authenticator = Auth
Dim Request As New WebRequest
Request.Resource = "sync"
Request.AddQuerystringParam "seq_no", 0
Request.AddQuerystringParam "seq_no_global", 0
Request.AddQuerystringParam "resource_types", "[""projects""]"
Dim Response As WebResponse
Set Response = TodoistClient.Execute(Request)
If Response.StatusCode = WebStatusCode.Ok Then
CountProjects = Response.Data("Projects").Count
End If
End Function
~~~
### [](https://github.com/VBA-tools/VBA-Web/wiki/Todoist-API#links)鏈接:
* [Todoist API Documentation](https://developer.todoist.com/)
* [Todoist OAuth](https://developer.todoist.com/#oauth)
* [Todoist App Management Console](https://developer.todoist.com/appconsole.html)
- README
- 指南
- 概述
- GET Request
- WebRequest
- 屬性
- Resource
- Method
- Body
- Format
- RequestFormat
- ResponseFormat
- CustomRequestFormat
- CustomResponseFormat
- ContentType
- Accept
- ContentLength
- FormattedResource
- Cookies
- Headers
- QuerystringParams
- UrlSegments
- 方法
- AddHeader
- SetHeader
- AddUrlSegment
- AddQuerystringParam
- AddCookie
- AddBodyParameter
- CreateFromOptions
- WebClient
- 屬性
- BaseUrl
- Authenticator
- TimeoutMs
- ProxyServer
- ProxyBypassList
- ProxyUsername
- ProxyPassword
- EnableAutoProxy
- Insecure
- FollowRedirects
- 方法
- Execute
- GetJson
- PostJson
- SetProxy
- GetFullUrl
- WebResponse
- 屬性
- StatusCode
- StatusDescription
- Content
- Data
- Body
- Headers
- Cookies
- 方法
- Update
- WebHelpers
- 屬性
- WebStatusCode
- WebMethod
- WebFormat
- UrlEncodingMode
- EnableLogging
- 方法
- LogDebug
- LogWarning
- LogError
- LogRequest
- LogResponse
- Obfuscate
- ParseJson
- ConvertToJson
- ParseUrlEncoded
- ConvertToUrlEncoded
- ParseXml
- ConvertToXml
- ParseByFormat
- ConvertToFormat
- UrlEncode
- UrlDecode
- Base64Encode
- Base64Decode
- RegisterConverter
- JoinUrl
- UrlParts
- CloneDictionary
- CloneCollection
- CreateKeyValue
- FindInKeyValues
- AddOrReplaceInKeyValues
- FormatToMediaType
- MethodToName
- HMACSHA1
- HMACSHA256
- MD5
- CreateNonce
- IWebAuthenticator
- 方法
- BeforeExecute
- AfterExecute
- PrepareHttp
- PrepareCurl
- WebAsyncWrapper
- 屬性
- Client
- 方法
- ExecuteAsync
- 范例
- Salesforce網站
- Google APIs
- Todoist API
- 其他主題
- 調試
- 授權
- 實現自己的IWebAuthenticator
- Url編碼