# 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编码