Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display Google Tasks #585

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Display Google Tasks #585

wants to merge 7 commits into from

Conversation

ewen-lbh
Copy link

@ewen-lbh ewen-lbh commented Feb 6, 2021

One concern is that already-logged-in users will have to clear their auth cache and re-auth when upgrading, or else it'll fail with permission errors while trying to access self.tasks_service

Closes #337
Closes #558
Closes #221

Note: this PR does not attempt to provide full Tasks integration (ie the ability to add or edit tasks), only the displaying of it.
I may attempt this in another PR though.

@ewen-lbh ewen-lbh changed the title google-tasks Display Google Tasks Feb 6, 2021
@ewen-lbh
Copy link
Author

ewen-lbh commented Feb 6, 2021

It seems like I can't mark the pull request as a draft

@ewen-lbh
Copy link
Author

ewen-lbh commented Feb 6, 2021

I get the following when trying to request the Tasks API (while authenticated):

HttpError 403 when requesting https://tasks.googleapis.com/tasks/v1/users/@me/lists?alt=json returned "Tasks API has not been used in project 905806700719 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/tasks.googleapis.com/overview?project=905806700719 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.". Details: "Tasks API has not been used in project 905806700719 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/tasks.googleapis.com/overview?project=905806700719 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."

@insanum, you might want to enable tasks v1 in your API Console

@ewen-lbh
Copy link
Author

ewen-lbh commented Feb 6, 2021

I can start developing without it, but it'll be more difficult. I'll start anyways

@insanum
Copy link
Owner

insanum commented Feb 8, 2021

I enabled the Tasks API to the gcalcli Google project. Let me know if you run into issues.

@ewen-lbh
Copy link
Author

ewen-lbh commented Feb 10, 2021

Ah, it still says that it's not enabled. I tried deleting ~/.gcalcli_oauth and ~/.gcalcli_cache, without success. Can you tell me what version of the Google Tasks API you enabled, so that I can choose the correct one? (In case there's something more recent than v1)

Here's the stdout just in case:

/home/ewen/.cache/pypoetry/virtualenvs/gcalcli-xBV0FQLW-py3.9/lib/python3.9/site-packages/oauth2client/_helpers.py:255: UserWarning: Cannot access /home/ewen/.gcalcli_oauth: No such file or directory
  warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
Ouverture dans une session de navigateur existante.

Your browser has been opened to visit:

    https://accounts.google.com/o/oauth2/v2/auth?client_id=905806700719-t5vnoihjo24n4jogi0p64mdijm5h181c.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Ftasks&access_type=offline&response_type=code

If your browser is on a different machine then exit and re-run this
application with the command-line parameter

  --noauth_local_webserver

Authentication successful.
Traceback (most recent call last):
  File "/home/ewen/.cache/pypoetry/virtualenvs/gcalcli-xBV0FQLW-py3.9/bin/gcalcli", line 5, in <module>
    main()
  File "/home/ewen/projects/gcalcli/gcalcli/cli.py", line 152, in main
    gcal.AgendaQuery(start=parsed_args.start, end=parsed_args.end)
  File "/home/ewen/projects/gcalcli/gcalcli/gcal.py", line 1267, in AgendaQuery
    return self._display_queried_events(start, end)
  File "/home/ewen/projects/gcalcli/gcalcli/gcal.py", line 1212, in _display_queried_events
    tasks_list = self._search_for_tasks(start, end, search)
  File "/home/ewen/projects/gcalcli/gcalcli/gcal.py", line 1171, in _search_for_tasks
    for tasklist in self.tasks_service.tasklists().list().execute():
  File "/home/ewen/.cache/pypoetry/virtualenvs/gcalcli-xBV0FQLW-py3.9/lib/python3.9/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/ewen/.cache/pypoetry/virtualenvs/gcalcli-xBV0FQLW-py3.9/lib/python3.9/site-packages/googleapiclient/http.py", line 915, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://tasks.googleapis.com/tasks/v1/users/@me/lists?alt=json returned "Tasks API has not been used in project 905806700719 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/tasks.googleapis.com/overview?project=905806700719 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.". Details: "Tasks API has not been used in project 905806700719 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/tasks.googleapis.com/overview?project=905806700719 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.">

@insanum
Copy link
Owner

insanum commented Feb 10, 2021

I'm not going to claim to understand the whole Google Cloud API management as it's presented today (vs when gcalcli was started many years ago). :-)

Here is what I see on the console. One thing I noticed in your error message is the project number 9058xxx... isn't the same project number. Did you create your own project for calendar API access?

Screen Shot 2021-02-10 at 11 07 08 AM

@ewen-lbh
Copy link
Author

hm... All I did was add a service via build:

self.tasks_service = build(
                serviceName="tasks", version="v1", http=self._google_auth()
            )

using self._google_auth().

Maybe I shouldn't be calling _google_auth again but re-use the returned object in both build calls? I'll try that and see how it goes.

@ewen-lbh
Copy link
Author

Still no success, it gives the same error message and refers to project 905806700719

@ewen-lbh
Copy link
Author

Even weirder, the web auth flow still displays gcalcli as the application name, as if it was the correct project

@ewen-lbh
Copy link
Author

ewen-lbh commented Feb 11, 2021

It seems like it indeed created a new 'gcalcli' project on my own google account automatically (which bizarre in and of itself) without me changing anything in the __API_CLIENT_*__ constants. I was able to activate the Google Tasks API by myself, and will develop with that setup. I just hope that it correctly uses your project instead of mine when this PR gets merged, but I guess that we'll have to wait & see...

@ewen-lbh ewen-lbh marked this pull request as draft February 23, 2021 18:49
@ewen-lbh
Copy link
Author

ewen-lbh commented Apr 9, 2021

So i'm not too sure about how to integrate it into the gigantic GoogleCalendarInterface -- should I make something separate?
Also, for the --tsv output, since tasks have different data from events, should we add an option to only output events or tasks? Should a new column be added to indicate whether the line describes a task or an event?

I didn't have much time lastly to work on this PR, but I'm motivated to get it done by May

@insanum
Copy link
Owner

insanum commented Apr 9, 2021

I don't have an opinion one way or the other. Only thing I suggest is do whatever feels right and makes the most sense.

@ewen-lbh
Copy link
Author

ewen-lbh commented Apr 13, 2021

@michaelmhoffman I saw your PR w/ the huge refactoring of _tsv(). How should I go about integrating Tasks with those new Handler classes?

EDIT: To clarify, would adding a type field that is either event or task be useful? And how should I got about implementing that?

@ron0studios
Copy link

Out of curiosity, how close are you to getting this completed?

@ewen-lbh
Copy link
Author

@rudrrayan still waiting for @michaelmhoffman to answer my question. I don't really want to mess up the project's architecture, since it's quite large.

@michaelmhoffman
Copy link
Collaborator

@ewen-lbh I'm not familiar with the Google Tasks API (or even Tasks as an end-user at all) unfortunately. Skimming the API it does not seem like there is a lot of overlap between the fields of an event and a task. The general pattern might be useful for you. Will discuss that below.

Would it make sense to have a separate entry points for working with tasks? I don't use tasks myself but feel they are rather orthogonal to calendar events and am not sure I would want gcalcli agenda to start listing tasks as well as events? A couple of alternatives would be:

  1. Creating a top-level gtaskcli command and then you could implement whichever subcommands make sense
  2. Creating a subcommand for viewing tasks (gcalcli tasks)

Doing this will also keep the tasks code relatively self-contained which will make it easier for people to edit it without stepping on the toes of people working on events and vice versa. And if that's the case I don't think many will care much how you implement it.

If you would like to use something like details.Handler in your implementation, my suggestion is to duplicate the file making a task_details.py, and then change things so that they fit the task interface.

@dbarnett
Copy link
Collaborator

Hey there, just checking in to mention I'm available now as a maintainer to review this if you still want to get it finished up and merged. =)

About the APIs, the good news / bad news is that there's no longer a centralized Google Cloud project ID for this, so everyone needs to configure the project settings for themselves but they have full control over the options...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gcalcli Google Tasks support Calendar Reminders and Tasks Tasks do not show up in gcalcli
5 participants