- Notifications
You must be signed in to change notification settings - Fork0
Google Tasks Go API Simplified
License
NotificationsYou must be signed in to change notification settings
jtsalva/tasq
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Built on top ofgoogle.golang.org/api/tasks/v1 adding extra functionality making it easier to get started with the Google Tasks API in Golang.
- Enable Google Tasks API fromAPI Console
- Create a new OAuth Client ID credential and download it as JSON
- Configure your OAuth consent screen
- Understand the conceptsdevelopers.google.com/tasks/concepts
- Get tasq
go get -u github.com/jtsalva/tasq
- Import tasq
import "github.com/jtsalva/tasq"
tasq.Init(&tasq.QConfig{// Either QTasksReadWriteScope or QTasksReadOnlyScopeScope:tasq.QTasksReadWriteScope,Credentials:"/path/to/credentials.json",})// Direct users here to grant access to your// application from their Google accountsauthURL:=tasq.Auth.GetAuthCodeURL()// Once the user grants access and is// redirected to your specified URL, grab// the code from the query stringauthCode:="4/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXX"// The auth code can only be used once// to generate a token, the token is// reusable, store it somewhere safetoken,err:=tasq.Auth.GetToken(authCode)// Create new service using tokensvc,err:=tasq.NewService(token)// List all Taskliststasklists,err:=svc.Tasklists.List().Do()// List Tasks from Tasklisttasks,err:=svc.Tasks.List(tasklistId).Do()
// tasklists is of type QTaskListstasklists,err:=svc.Tasklists.List().Do()// tasklists.Items is of type []*QTaskListfor_,tasklist:=rangetasklists.Items {fmt.Println(tasklist.Id,tasklist.Name)}
// tasks is of type QTaskstasks,err:=svc.Tasks.List().Do()// tasks.Items is of type []*QTaskfor_,task:=rangetasks.Items {fmt.Println(task.Id,task.Title,task.Notes)// List sub-tasks of task// task.Children is of type []*QTaskfor_,child:=rangetask.Children {fmt.Println("\t",child.Id,child.Title,child.Notes) }}
Fllter by either
QCompletedFilter
- show only completed tasksQNeedsActionFilter
- show only tasks needing actionQOverdueFilter
- show only tasks needing action where the datetime now is more than the due datetime
filteredTasks,err:=svc.Tasks.List().Filter(tasq.QOverdueFilter).Do()
Additionally, you can sort your items either by
QPositionSort
- sort in the way the user positioned the tasksQLatestFirstSort
- newly updated tasks firstQOldestFirstSort
- oldest updated tasks first
sortedTasks,err:=svc.Tasks.List().Sort(tasq.QPositionSort).Do()
You can combine filter and sort
filterdAndSortedTasks,err:=svc.Tasks.List().Filter(filter).Sort(sort).Do()
You can directly manipulate and perform actions on aQTaskList
andQTask
.
// tasklist is of type QTaskListtasklist,err:=svc.Tasklists.Get(tasklistid).Do()// task is of type QTasktask,err:=svc.Tasks.Get(tasklistid,taskid).Do()
- Deleting
- Inserting
- Updating
- Refreshing
- Move to Parent
- Move to Previous
- Move to Beginning
- Get Time of Last Update
// Delete a list, including the tasks and subtasks within iterr:=tasklist.Delete()// Delete a single taskerr:=task.Delete()
Insert a task into another list
insertedTask,err:=task.Insert(anotherTasklistid)
tasklist.Title="change tasklist title"updatedTasklist,err:=tasklist.Update()task.Title="change task title"updatedTask,err:=task.Update()
If there have been remote changes, update the data currently stored in memory
err:=tasklist.Refresh()err:=task.Refresh()
Make task a subtask to the given parent task id
movedTask,err:=task.MoveToParent(parentTaskid)
Move task after given previous task id
movedTask,err:=task.MoveToPrevious(previousTaskid)
Moves task to beginning of list
movedTask,err:=task.MoveToBeginning()
Returns time of last update as typetime.Time
tasklistUpdatedTime,err:=tasklist.Time()taskUpdatedTime,err:=task.Time()