Comments (11)
@d60 Works great. The best library ever!!
from twikit.
@david-lev Thanks! i'll get to work on it right away, but it may take some time. If you need to use the functionality immediately, change the UPLOAD_MEDIA endpoint on line 206 of twikit/utils.py.
from twikit.
@david-lev Added is_long_video
argument in version 1.5.13 .You can upload long videos by setting this argument to True.
from twikit.
Anybody?
from twikit.
@david-lev That's because the video upload is not yet complete. Set wait_for_completion
to True to wait until the upload is complete.
media_id = await client.upload_media(source=video_bytes, wait_for_completion=True, media_type="video/mp4")
from twikit.
@d60 Thanks for your help. I try to wait_for_completion but I'm getting this err now:
2024-05-01 21:09:34 - root - ERROR - Error while uploading media to Twitter: 'coroutine' object is not subscriptable
Traceback (most recent call last):
File "/app/tw.py", line 24, in post_tweet
[await client.upload_media(source=media, wait_for_completion=True) for media in medias]
File "/app/tw.py", line 24, in <listcomp>
[await client.upload_media(source=media, wait_for_completion=True) for media in medias]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/twikit/twikit_async/client.py", line 771, in upload_media
processing_info = state['processing_info']
~~~~~^^^^^^^^^^^^^^^^^^^
TypeError: 'coroutine' object is not subscriptable
/app/tw.py:30: RuntimeWarning: coroutine 'Client.check_media_status' was never awaited
return
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
from twikit.
Okay, I 'awaited' manually for check_media_status
and when processing_info["state"] == "succeeded"
I posted the tweet. this the err in got:
Traceback (most recent call last):
File "/app/tg.py", line 83, in post_to_twitter
tweet = await tw.post_tweet(
^^^^^^^^^^^^^^^^^^^^
File "/app/tw.py", line 45, in post_tweet
return await client.create_tweet(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/twikit/twikit_async/client.py", line 1119, in create_tweet
raise_exceptions_from_response(response['errors'])
File "/usr/local/lib/python3.11/site-packages/twikit/errors.py", line 100, in raise_exceptions_from_response
raise exception(error['message'])
twikit.errors.InvalidMedia: BadRequest: Duration too long, maximum:2.minutes+20.seconds, actual:4.minutes+33.seconds+400.milliseconds (MediaId: snf:1785736xxxx5488) (324)
from twikit.
@d60 Thanks for your help. I try to wait_for_completion but I'm getting this err now:
2024-05-01 21:09:34 - root - ERROR - Error while uploading media to Twitter: 'coroutine' object is not subscriptable Traceback (most recent call last): File "/app/tw.py", line 24, in post_tweet [await client.upload_media(source=media, wait_for_completion=True) for media in medias] File "/app/tw.py", line 24, in <listcomp> [await client.upload_media(source=media, wait_for_completion=True) for media in medias] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/twikit/twikit_async/client.py", line 771, in upload_media processing_info = state['processing_info'] ~~~~~^^^^^^^^^^^^^^^^^^^ TypeError: 'coroutine' object is not subscriptable /app/tw.py:30: RuntimeWarning: coroutine 'Client.check_media_status' was never awaited return RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Sorry I forgot to add "await". I have just released version 1.5.12 and fixed that.
from twikit.
Okay, I 'awaited' manually for
check_media_status
and whenprocessing_info["state"] == "succeeded"
I posted the tweet. this the err in got:Traceback (most recent call last): File "/app/tg.py", line 83, in post_to_twitter tweet = await tw.post_tweet( ^^^^^^^^^^^^^^^^^^^^ File "/app/tw.py", line 45, in post_tweet return await client.create_tweet( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/twikit/twikit_async/client.py", line 1119, in create_tweet raise_exceptions_from_response(response['errors']) File "/usr/local/lib/python3.11/site-packages/twikit/errors.py", line 100, in raise_exceptions_from_response raise exception(error['message']) twikit.errors.InvalidMedia: BadRequest: Duration too long, maximum:2.minutes+20.seconds, actual:4.minutes+33.seconds+400.milliseconds (MediaId: snf:1785736xxxx5488) (324)
That error is probably because you are trying to upload a video longer than the maximum size (2 minutes 20 seconds).
from twikit.
wow you are fast.. thanks!!
Premium accounts can upload longer videos. Is it possible to add support for this in the library? I can check the endpoints
from twikit.
- Start upload
curl 'https://upload.twitter.com/i/media/upload2.json?command=INIT&total_bytes=30034657&media_type=video%2Fmp4&video_duration_ms=273400&media_category=tweet_video' \
-X 'POST' \
-H 'accept: */*' \
-H 'accept-language: en-US,en;q=0.9,he;q=0.8,he-IL;q=0.7' \
-H 'authorization: Bearer xxxxx' \
-H 'cache-control: no-cache' \
-H 'content-length: 0' \
-H 'cookie: kdt=VABcmEXj4RA=="' \
-H 'dnt: 1' \
-H 'origin: https://twitter.com' \
-H 'pragma: no-cache' \
-H 'priority: u=1, i' \
-H 'referer: https://twitter.com/' \
-H 'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"' \
-H 'sec-ch-ua-mobile: ?1' \
-H 'sec-ch-ua-platform: "Android"' \
-H 'sec-fetch-dest: empty' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-site: same-site' \
-H 'user-agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36' \
-H 'x-csrf-token: xxxx' \
-H 'x-twitter-auth-type: OAuth2Session'
- Continue upload:
curl 'https://upload.twitter.com/i/media/upload2.json?command=APPEND&media_id=1785xxxxx7391488&segment_index=0' \
-X 'OPTIONS' \
-H 'accept: */*' \
-H 'accept-language: en-US,en;q=0.9,he;q=0.8,he-IL;q=0.7' \
-H 'access-control-request-headers: authorization,x-csrf-token,x-twitter-auth-type' \
-H 'access-control-request-method: POST' \
-H 'cache-control: no-cache' \
-H 'origin: https://twitter.com' \
-H 'pragma: no-cache' \
-H 'priority: u=1, i' \
-H 'referer: https://twitter.com/' \
-H 'sec-fetch-dest: empty' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-site: same-site' \
-H 'user-agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36'
- Post tweet (after upload & process is done):
curl 'https://twitter.com/i/api/graphql/zIdRTsSqcD6R5uMtm_N0pw/CreateTweet' \
-H 'accept: */*' \
-H 'accept-language: en-US,en;q=0.9,he;q=0.8,he-IL;q=0.7' \
-H 'authorization: Bearer xxxxxxx' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'cookie: xxxxxx' \
-H 'dnt: 1' \
-H 'origin: https://twitter.com' \
-H 'pragma: no-cache' \
-H 'priority: u=1, i' \
-H 'referer: https://twitter.com/compose/post' \
-H 'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"' \
-H 'sec-ch-ua-mobile: ?1' \
-H 'sec-ch-ua-platform: "Android"' \
-H 'sec-fetch-dest: empty' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-site: same-origin' \
-H 'user-agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36' \
-H 'x-client-transaction-id: xxxx' \
-H 'x-csrf-token: xxxxxxx' \
-H 'x-twitter-active-user: yes' \
-H 'x-twitter-auth-type: OAuth2Session' \
-H 'x-twitter-client-language: he' \
--data-raw '{"variables":{"tweet_text":"test","dark_request":false,"media":{"media_entities":[{"media_id":"1785xxxxx91488","tagged_users":[]}],"possibly_sensitive":false},"semantic_annotation_ids":[]},"features":{"communities_web_enable_tweet_community_results_fetch":true,"c9s_tweet_anatomy_moderator_badge_enabled":true,"tweetypie_unmention_optimization_enabled":true,"responsive_web_edit_tweet_api_enabled":true,"graphql_is_translatable_rweb_tweet_is_translatable_enabled":true,"view_counts_everywhere_api_enabled":true,"longform_notetweets_consumption_enabled":true,"responsive_web_twitter_article_tweet_consumption_enabled":true,"tweet_awards_web_tipping_enabled":false,"creator_subscriptions_quote_tweet_preview_enabled":false,"longform_notetweets_rich_text_read_enabled":true,"longform_notetweets_inline_media_enabled":true,"articles_preview_enabled":true,"rweb_video_timestamps_enabled":true,"rweb_tipjar_consumption_enabled":true,"responsive_web_graphql_exclude_directive_enabled":true,"verified_phone_label_enabled":false,"freedom_of_speech_not_reach_fetch_enabled":true,"standardized_nudges_misinfo":true,"tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled":true,"tweet_with_visibility_results_prefer_gql_media_interstitial_enabled":true,"responsive_web_graphql_skip_user_profile_image_extensions_enabled":false,"responsive_web_graphql_timeline_navigation_enabled":true,"responsive_web_enhance_cards_enabled":false},"queryId":"zIxxxxxuMtm_N0pw"}'
from twikit.
Related Issues (20)
- get_tweet_by_id() throws IndexError HOT 1
- Fetching posts HOT 1
- pool HOT 1
- Can I retrieve the number of tweets without an account? HOT 1
- Login method support TOTP code. HOT 4
- rate limitations HOT 6
- monitor reply,like tweets or retweet? HOT 4
- Auto Phone Number
- Login is not working HOT 1
- Unable to get follower counts
- status: 401, message: "{"errors":[{"message":"Could not authenticate you","code":32}]}
- Can't pull more than 100 tweets HOT 2
- I can't use get_dm_history() HOT 1
- logout function error HOT 1
- have an API to get comments? HOT 2
- Tweet Full Text issue HOT 2
- Retrieving New DMs and Bell Activation HOT 1
- Wrong value 'verified' property
- Rate Limit Issue with get_tweet_by_id “twikit.errors.TooManyRequests: status: 429”
- **使用这个库登录是不是需要加入国外代理ip HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from twikit.