You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am pretty new to Python or coding in general and I am trying to set up my raspberry Pi zero to tweet Gifs. Unfortunately I had no luck so far, I managed to make a normal tweet but whenever I try it with a JPEG or a GIF the Python script just times out.
print('Posting to Twitter')
photo = open('/home/pi/gifcam/gifs/test_1.jpg', 'rb')
response = twitter.upload_media(media=photo)
twitter.update_status(status='Taken with #PIX-E Gif Camera', media_ids=[response['media_id']])
`
I was looking into the Twython code a bit and found these lines below from endpoints.py for the media upload. I was wondering if the problem result from the the fact that the media.upload doesn't go through the same three stages like the upload.video (INIT, APPEND, FINALIZE) as described in the Twitter API documentation chunked POST media/upload
Every help with this issue is much appreciated.
Thanks and best regards
david
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
to a status for 60 minutes. To attach to a update, pass a list of returned media ids
to the :meth:update_status method using the media_ids param.
Upload happens in 3 stages:
- INIT call with size of media to be uploaded(in bytes). If this is more than 15mb, twitter will return error.
- APPEND calls each with media chunk. This returns a 204(No Content) if chunk is received.
- FINALIZE call to complete media upload. This returns media_id to be used with status update.
Twitter media upload api expects each chunk to be not more than 5mb. We are sending chunk of 1mb each.
Docs: https://developer.twitter.com/en/docs/media/upload-media/uploading-media/chunked-media-upload
`
The text was updated successfully, but these errors were encountered:
new-yen
changed the title
Chunked media upload
Chunked media upload keeps timing out
Mar 29, 2018
The missing chunked upload might still lead to problems with bigger file sizes, which was not an issue in my case, as I only tried to upload small images and GIFs.
But I made the upload work for me. I figured out, that my problem was, that I tried running my script in Python 3 but it only works in Python 2.
I think this is worth mentioning and maybe should go in a pull request or did I just miss this information somehow.
Hello,
I am pretty new to Python or coding in general and I am trying to set up my raspberry Pi zero to tweet Gifs. Unfortunately I had no luck so far, I managed to make a normal tweet but whenever I try it with a JPEG or a GIF the Python script just times out.
This is the code I have been trying:
`
from twython import Twython
APP_KEY = 'my APP_KEY'
APP_SECRET = 'my APP_SECRET'
OAUTH_TOKEN = 'my OAUTH_TOKEN'
OAUTH_TOKEN_SECRET = 'my OAUTH_TOKEN_SECRET'
twitter = Twython(APP_KEY,
APP_SECRET,
OAUTH_TOKEN,
OAUTH_TOKEN_SECRET)
print('Posting to Twitter')
photo = open('/home/pi/gifcam/gifs/test_1.jpg', 'rb')
response = twitter.upload_media(media=photo)
twitter.update_status(status='Taken with #PIX-E Gif Camera', media_ids=[response['media_id']])
`
I was looking into the Twython code a bit and found these lines below from endpoints.py for the media upload. I was wondering if the problem result from the the fact that the media.upload doesn't go through the same three stages like the upload.video (INIT, APPEND, FINALIZE) as described in the Twitter API documentation chunked POST media/upload
Every help with this issue is much appreciated.
Thanks and best regards
david
This is the code from "endpoints.py" for the media upload:
def upload_media(self, **params): """Uploads media file to Twitter servers. 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 the :meth:
update_status` method using themedia_ids
param.Docs:
https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload
"""
# https://developer.twitter.com/en/docs/media/upload-media/api-reference/get-media-upload-status
if params and params.get('command', '') == 'STATUS':
return self.get('https://upload.twitter.com/1.1/media/upload.json', params=params)
for the video upload:
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
to a status for 60 minutes. To attach to a update, pass a list of returned media ids
to the :meth:
update_status
method using themedia_ids
param.Upload happens in 3 stages:
- INIT call with size of media to be uploaded(in bytes). If this is more than 15mb, twitter will return error.
- APPEND calls each with media chunk. This returns a 204(No Content) if chunk is received.
- FINALIZE call to complete media upload. This returns media_id to be used with status update.
Twitter media upload api expects each chunk to be not more than 5mb. We are sending chunk of 1mb each.
Docs:
https://developer.twitter.com/en/docs/media/upload-media/uploading-media/chunked-media-upload
`
The text was updated successfully, but these errors were encountered: