Hootsweet
A python API for the HootSuite REST API.
Installation
pip install hootsweet
Usage
from hootsweet import HootSweet
client_id = "Your-HootSuite-Client-ID"
client_secret = "Your-HootSuite-Client-Secret"
redirect_uri = "http://redirect.uri/"
def handle_refresh(token):
# callback function to save token to a database or file
save_token_to_db(token)
client = HootSweet(client_id, client_secret, redirect_uri=redirect_uri, refresh_cb=handle_refresh)
# Step 1 get authorization url from HootSuite
url, state = client.authorization_url()
# Step 2 go to url above and get OAuth2 code
token = client.fetch_token(code)
# client.token now contains your authentication token
# Step 3 (optional) refresh token periodically, this automatically calls handle_refresh
token = client.refresh_token()
# retrieve data from https://platform.hootsuite.com/v1/me
me = client.get_me()
# retrieve authenticated members organizations https://platform.hootsuite.com/v1/me/organizations
organizations = client.get_me_organizations()
Messages
token = {
"access_token": "e9a90a81-xf2d-dgh3-cfsd-23jhvn76",
"token_Type": "Bearer",
"expires_in": 2592000,
"refresh_token": "82d82cf4-76gf-gfds-nt3k-lzpo12jg",
"scope": "offline"
}
client = HootSweet("client_id", "client_secret", token=token)
# Schedule a message
text = "A message"
social_profile_ids = ["1234", "12345"]
send_time = datetime(2020, 1, 1, 12, 40, 15)
message = client.schedule_message(text=text, social_profile_ids=social_profile_ids,
send_time=send_time)
# Get message
message = client.get_message(message_id="98765")
# Delete message
client.delete_message(message_id="98765")
Messages with Media
HootSuite uses it’s own AWS Bucket to add media to a message. To attach media to you message you need to first upload the media to HootSuite’s bucket.
token = {
"access_token": "e9a90a81-xf2d-dgh3-cfsd-23jhvn76",
"token_Type": "Bearer",
"expires_in": 2592000,
"refresh_token": "82d82cf4-76gf-gfds-nt3k-lzpo12jg",
"scope": "offline"
}
client = HootSweet("client_id", "client_secret", token=token)
mime_type = "image/png"
file_path = Path("/path/to/file.png")
file_size = file_path.stat().st_size
upload_details = client.create_media_upload_url(file_size, mime_type)
upload_url = upload_details["uploadUrl"]
media_id = upload_details["id"]
# The number of seconds you have to upload the media
expires_in = upload_details["uploadUrlDurationSeconds"]
# Upload the media
with file_path.open("rb") as f:
content = f.read()
headers = {"Content-Type": mime_type, "Content-Length": str(file_size)}
# Make sure that this request returns a 200
requests.put(upload_url, headers=headers, data=content)
# Schedule a message
text = "A message"
social_profile_ids = ["1234", "12345"]
send_time = datetime(2020, 1, 1, 12, 40, 15)
media = [{"id": media_id}]
message = client.schedule_message(text=text, social_profile_ids=social_profile_ids,
send_time=send_time, media=media)
Metadata
Release files for hootsweet 0.7.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hootsweet-0.7.1.tar.gz | 8.6 kB | Without provenance | Details for hootsweet-0.7.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hootsweet-0.7.1-py3-none-any.whl | Python 3 | none | any | Details for hootsweet-0.7.1-py3-none-any.whl |
Total release size: 16.3 kB
Release files / hootsweet-0.7.1.tar.gz
| Download URL | hootsweet-0.7.1.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b22ead1f9e5790f3507af448e65a530bfb5afbbb31dbe18da33a280a9e09e78
|
|
BLAKE2b-256 checksum How to use checksums |
b0f4d4b6b2cb80dc850c191f443a6871b7d5f0dc318e9d2b92c6336fee48fdeb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.10 CPython/3.8.5 Linux/5.3.0-1034-azure
|
Release files / hootsweet-0.7.1-py3-none-any.whl
| Download URL | hootsweet-0.7.1-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e52a1ce7b820ffe84e94afbb6b9b8e0c5872714e4b51333f7d47b0fba350294e
|
|
BLAKE2b-256 checksum How to use checksums |
35616b6d02fbadce4cd6aaed3f197c12cb055b5a3c60dae42c7e9740fbd546d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.10 CPython/3.8.5 Linux/5.3.0-1034-azure
|
Security for hootsweet 0.7.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.