Created
January 27, 2025 00:16
-
-
Save idkwebdev/a21b7872a60d167445b506c9f7a26488 to your computer and use it in GitHub Desktop.
TickTick OAuth Helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from requests.auth import HTTPBasicAuth as Auth | |
url = 'https://ticktick.com/oauth/authorize?scope=tasks:write%20tasks:read&client_id={client_id}&state=state&redirect_uri=https://www.example.com/&response_type=code' | |
print('Welcome to the TickTick API OAuth2.0 setup.') | |
print('Before beginning, go to "https://developer.ticktick.com/manage" and create a new app.') | |
print('Under "OAuth redirect URL", add "https://www.example.com/"') | |
print() | |
client_id = input('What is your client ID?\n> ') | |
client_secret = input('What is your client secret?\n> ') | |
print() | |
while True: | |
try: | |
print('Please go to the following link, accept permisstions, and paste the redirect url below.') | |
print() | |
print(url.format(client_id=client_id)) | |
redirect_link = input('> ') | |
query_parameters = redirect_link.split('?')[1].split('&') | |
code = next(arg.split('=')[1] for arg in query_parameters if 'code' in arg) | |
except StopIteration: | |
print('Try Again') | |
continue | |
break | |
token_req = requests.post( | |
'https://ticktick.com/oauth/token', | |
params={ | |
'code': code, | |
'grant_type': 'authorization_code', | |
'scope': 'tasks:read tasks:write', | |
'redirect_uri': 'https://www.example.com/', | |
'state': 'state', | |
}, | |
auth=Auth(client_id, client_secret) | |
) | |
token = token_req.json()['access_token'] | |
print(f'\nYour access token is "{token}"') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment