Merge pull request #460 from jmdaweb/master
Added create_metadata endpoint
This commit is contained in:
commit
7be654136e
2 changed files with 17 additions and 4 deletions
|
|
@ -140,7 +140,11 @@ class Twython(EndpointsMixin, object):
|
||||||
params = params or {}
|
params = params or {}
|
||||||
|
|
||||||
func = getattr(self.client, method)
|
func = getattr(self.client, method)
|
||||||
params, files = _transparent_params(params)
|
if isinstance(params, dict):
|
||||||
|
params, files = _transparent_params(params)
|
||||||
|
else:
|
||||||
|
params = params
|
||||||
|
files = list()
|
||||||
|
|
||||||
requests_args = {}
|
requests_args = {}
|
||||||
for k, v in self.client_args.items():
|
for k, v in self.client_args.items():
|
||||||
|
|
@ -192,15 +196,16 @@ class Twython(EndpointsMixin, object):
|
||||||
error_message,
|
error_message,
|
||||||
error_code=response.status_code,
|
error_code=response.status_code,
|
||||||
retry_after=response.headers.get('X-Rate-Limit-Reset'))
|
retry_after=response.headers.get('X-Rate-Limit-Reset'))
|
||||||
|
content = ''
|
||||||
try:
|
try:
|
||||||
if response.status_code == 204:
|
if response.status_code == 204:
|
||||||
content = response.content
|
content = response.content
|
||||||
else:
|
else:
|
||||||
content = response.json()
|
content = response.json()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise TwythonError('Response was not valid JSON. \
|
if response.content != '':
|
||||||
Unable to decode.')
|
raise TwythonError('Response was not valid JSON. \
|
||||||
|
Unable to decode.')
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ This map is organized the order functions are documented at:
|
||||||
https://dev.twitter.com/docs/api/1.1
|
https://dev.twitter.com/docs/api/1.1
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import warnings
|
import warnings
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
@ -150,6 +151,13 @@ class EndpointsMixin(object):
|
||||||
|
|
||||||
return self.post('https://upload.twitter.com/1.1/media/upload.json', params=params)
|
return self.post('https://upload.twitter.com/1.1/media/upload.json', params=params)
|
||||||
|
|
||||||
|
def create_metadata(self, **params):
|
||||||
|
""" Adds metadata to a media element, such as image descriptions for visually impaired.
|
||||||
|
Docs: https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-metadata-create
|
||||||
|
"""
|
||||||
|
params = json.dumps(params)
|
||||||
|
return self.post("https://upload.twitter.com/1.1/media/metadata/create.json", params=params)
|
||||||
|
|
||||||
def upload_video(self, media, media_type, media_category=None, size=None, check_progress=False):
|
def upload_video(self, media, media_type, media_category=None, size=None, check_progress=False):
|
||||||
"""Uploads video file to Twitter servers in chunks. The file will be available to be attached
|
"""Uploads video file to Twitter servers in chunks. The file will be available to be attached
|
||||||
to a status for 60 minutes. To attach to a update, pass a list of returned media ids
|
to a status for 60 minutes. To attach to a update, pass a list of returned media ids
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue