mahrtayyab / tweety

Twitter Scraper
494 stars 67 forks source link

create_tweet() on premium+ account limits tweet length #199

Closed narodnik closed 1 day ago

narodnik commented 4 months ago
Traceback (most recent call last):
  File "/home/xyz/src/stuff/twat/./post.py", line 35, in <module>
    message = app.create_tweet(msg, files)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xyz/.local/lib/python3.12/site-packages/tweety/utils.py", line 44, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xyz/.local/lib/python3.12/site-packages/tweety/user.py", line 581, in create_tweet
    response = self.request.create_tweet(text, files, filter_, reply_to, quote, pool, place, batch_compose)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xyz/.local/lib/python3.12/site-packages/tweety/http.py", line 406, in create_tweet
    response = self.__get_response__(**request_data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xyz/.local/lib/python3.12/site-packages/tweety/http.py", line 185, in __get_response__
    return GenericError(
           ^^^^^^^^^^^^^
  File "/home/xyz/.local/lib/python3.12/site-packages/tweety/types/n_types.py", line 72, in __init__
    self._raise_exception()
  File "/home/xyz/.local/lib/python3.12/site-packages/tweety/types/n_types.py", line 92, in _raise_exception
    raise TwitterError(
tweety.exceptions.TwitterError: [186] Authorization: Tweet needs to be a bit shorter. (186)

I'm looking at the code in tweety, and it seems to be an error from Twitter. So maybe there's an alternative method we need to call?

How do you debug this? Are you using wireshark to examine the network traffic, or how can I examine the API?

narodnik commented 4 months ago

I found this link: https://devcommunity.x.com/t/how-to-post-280-4000-characters-via-api-v2/191156

so if tweety could do this then it would be able to do sth the normal API cannot do ;)

narodnik commented 4 months ago

Is this a good tool to intercept SSL traffic or do you recommend another workflow?

https://docs.mitmproxy.org/stable/overview-getting-started/

edit: ok I used my browser's inbuilt tools, here's what I've got for a short tweet:

{
  "variables": {
    "tweet_text": "dddd",
    "dark_request": false,
    "media": {
      "media_entities": [],
      "possibly_sensitive": false
    },
    "semantic_annotation_ids": [],
    "disallowed_reply_options": null
  },
  "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,
    "responsive_web_graphql_skip_user_profile_image_extensions_enabled": false,
    "responsive_web_graphql_timeline_navigation_enabled": true,
    "responsive_web_enhance_cards_enabled": false
  },
  "queryId": "..."
}

but when I made a long tweet, instead it called CreateNoteTweet, and here's the POST data:


{
  "variables": {
    "tweet_text": "....",
    "dark_request": false,
    "media": {
      "media_entities": [],
      "possibly_sensitive": false
    },
    "semantic_annotation_ids": [],
    "disallowed_reply_options": null
  },
  "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,
    "responsive_web_graphql_skip_user_profile_image_extensions_enabled": false,
    "responsive_web_graphql_timeline_navigation_enabled": true,
    "responsive_web_enhance_cards_enabled": false
  },
  "queryId": "..."
}```

so it's basically the same API with just a different function name.

This is the URL: `https://x.com/i/api/graphql/0aWhJJmFlxkxv9TAUJPanA/CreateNoteTweet`
mahrtayyab commented 4 months ago

Yes Long tweet required to be sent to CreateNoteTweet , it will be added in next release

narodnik commented 4 months ago

BTW I notice a few differences between builder.py and my output above:

    "tweet_awards_web_tipping_enabled": false,
    "creator_subscriptions_quote_tweet_preview_enabled": false,
    "verified_phone_label_enabled": false,
mahrtayyab commented 1 day ago

https://github.com/mahrtayyab/tweety/commit/650981ce9605e6e06f2c5c1fe2db5c01a5270d2e