Using Threads API more easily
Project description
Threads SDK
Usage
Install package
pip install threads_sdk
Environment variables
Input those variables in your .env
file or OS environment (or using export
).
Then you don't need to input any parameters in initialize step
.
USER_ID
ACCESS_TOKEN
APP_SECRET
Initialize instance
- If you already have Notify environment variables:
from lotify.client import Client
client = Client()
- else:
from lotify.client import Client
client = Client(
client_id='YOUR_CLIENT_ID',
client_secret='YOUR_CLIENT_SECRET',
redirect_uri='YOUR_URI'
)
Get authorizer link
link = client.get_auth_link(state='RANDOM_STRING')
print(link)
# https://notify-bot.line.me/oauth/authorize?scope=notify&response_type=code&client_id=QxUxF..........i51eITH&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Fnotify&state=foo
Get access token
access_token = client.get_access_token(code='NOTIFY_RESPONSE_CODE')
print(access_token)
# N6g50DiQZk5Xh...25FoFzrs2npkU3z
Get Status
status = client.status(access_token='YOUR_ACCESS_TOKEN')
print(status)
# {'status': 200, 'message': 'ok', 'targetType': 'USER', 'target': 'NiJia Lin'}
Send message
response = client.send_message(access_token='YOUR_ACCESS_TOKEN', message='This is notify message')
print(response)
# {'status': 200, 'message': 'ok'}
Send message with Sticker
You can find stickerId and stickerPackageId here.
response = client.send_message_with_sticker(
access_token='YOUR_ACCESS_TOKEN',
message='This is notify message',
sticker_id=1,
sticker_package_id=1)
print(response)
# {'status': 200, 'message': 'ok'}
Send message with Files
image = client.send_message_with_image_file(
access_token='YOUR_ACCESS_TOKEN',
message='This is notify message',
file=open('./test_image.png', 'rb')
)
print(image)
# {'status': 200, 'message': 'ok'}
Send message with Image url
image = client.send_message_with_image_url(
access_token='YOUR_ACCESS_TOKEN',
message='This is notify message',
image_thumbnail='https://i.imgur.com/RhvwZVm.png',
image_fullsize='https://i.imgur.com/RhvwZVm.png',
)
print(image)
# {'status': 200, 'message': 'ok'}
Revoke access token
revoke = client.revoke(access_token='YOUR_ACCESS_TOKEN')
print(revoke)
# {'status': 200, 'message': 'ok'}
Command Line Interface
lotify --help
-t, --access_token TEXT access token [required]
-m, --message TEXT message to send [required]
-u, --image-url TEXT image url to send
-f, --image-file TEXT image file path to send
Contributing
Fork before Clone the repository:
git clone git@github.com:your-username/line-notify.git
First install for development.
pip install -r requirements-dev.txt
Run pytest
to make sure the tests pass:
cd line-notify/
python -m tox
python -m pytest --flake8 tests/
Command Line Debug
If you met following logs.
Traceback (most recent call last):
File "/usr/local/bin/lotify", line 33, in <module>
sys.exit(load_entry_point('lotify==2.3.2', 'console_scripts', 'lotify')())
File "/usr/local/bin/lotify", line 25, in importlib_load_entry_point
return next(matches).load()
StopIteration
Uninstall old package and reinstall.
pip uninstall lotify
pip install lotify
Then StopIteration
would go away.
Contributors
License
MIT © NiJia Lin & Duncan Huang
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
threads_sdk-0.1.1.tar.gz
(6.7 kB
view details)
Built Distribution
File details
Details for the file threads_sdk-0.1.1.tar.gz
.
File metadata
- Download URL: threads_sdk-0.1.1.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cea0ee7bb8211ebb02e58bc3b4c1aef5990dce4100b8bf89557ba603d5548a4 |
|
MD5 | 1955674ffddd32d486b72d6226488fba |
|
BLAKE2b-256 | e2a145981e10bfa301f771fc7f9cd86865122d1c97b58c89cc3077b64a7aa279 |
File details
Details for the file threads_sdk-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: threads_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07f9e9bf20010a0f2d00f7621a7203c4e33a5c67fecdd670f74c0ca3e4ee213b |
|
MD5 | fc9704ebd0e73a2e823572ee9a36771b |
|
BLAKE2b-256 | 152ccf822e5f9a3b5bd7fcdcdb5eb60ab8861aa1eb1b16ba35358b7b9659e683 |