Media
This is a module for interacting with Twitter media
get_media_upload_status(media_id, twitter_credentials)
async
Check on the progress of a chunked media upload. If the upload has succeeded, it's safe to create a Tweet with this media_id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
media_id |
int
|
The ID of the media to check. |
required |
twitter_credentials |
TwitterCredentials
|
Credentials to use for authentication with Twitter. |
required |
Returns:
Type | Description |
---|---|
Media
|
The Media object. |
Example
Tweets an update with just text.
from prefect import flow
from prefect_twitter import TwitterCredentials
from prefect_twitter.media import get_media_upload_status
@flow
def example_get_media_upload_status_flow():
twitter_credentials = TwitterCredentials(
consumer_key=consumer_key,
consumer_secret=consumer_secret,
access_token=access_token,
access_token_secret=access_token_secret
)
media_id = 1443668738906234883
media = get_media_upload_status(media_id, twitter_credentials)
return media
example_get_media_upload_status_flow()
Source code in prefect_twitter/media.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
media_upload(filename, twitter_credentials, file=None, chunked=False, **kwargs)
async
Uploads media to Twitter. Chunked media upload is automatically used for videos.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
Union[Path, str]
|
The filename of the image to upload. This field is used for MIME type detection. |
required |
twitter_credentials |
TwitterCredentials
|
Credentials to use for authentication with Twitter. |
required |
file |
Optional[IOBase]
|
A file object to upload. If not specified, this task will attempt to locate and upload a file with the name specified in filename. |
None
|
chunked |
bool
|
Whether or not to use chunked media upload. Videos use chunked upload regardless of this parameter. |
False
|
kwargs |
dict
|
Additional keyword arguments to pass to media_upload. |
{}
|
Example
Uploads an image from a file path to Twitter.
from prefect import flow
from prefect_twitter import TwitterCredentials
from prefect_twitter.media import media_upload
@flow
def example_media_upload_flow():
twitter_credentials = TwitterCredentials(
consumer_key="consumer_key",
consumer_secret="consumer_secret",
access_token="access_token",
access_token_secret="access_token_secret"
)
media_id = media_upload("/path/to/prefection.jpg", twitter_credentials)
return media_id
example_media_upload_flow()
Source code in prefect_twitter/media.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|