TwitterTweetLoader#

class langchain_community.document_loaders.twitter.TwitterTweetLoader(auth_handler: OAuthHandler | OAuth2BearerHandler, twitter_users: Sequence[str], number_tweets: int | None = 100)[source]#

Load Twitter tweets.

Read tweets of the user’s Twitter handle.

First you need to go to https://developer.twitter.com/en/docs/twitter-api /getting-started/getting-access-to-the-twitter-api to get your token. And create a v2 version of the app.

Methods

__init__(auth_handler, twitter_users[, ...])

alazy_load()

A lazy loader for Documents.

aload()

Load data into Document objects.

from_bearer_token(oauth2_bearer_token, ...)

Create a TwitterTweetLoader from OAuth2 bearer token.

from_secrets(access_token, ...[, number_tweets])

Create a TwitterTweetLoader from access tokens and secrets.

lazy_load()

A lazy loader for Documents.

load()

Load tweets.

load_and_split([text_splitter])

Load Documents and split into chunks.

Parameters:
  • auth_handler (Union[OAuthHandler, OAuth2BearerHandler])

  • twitter_users (Sequence[str])

  • number_tweets (Optional[int])

__init__(auth_handler: OAuthHandler | OAuth2BearerHandler, twitter_users: Sequence[str], number_tweets: int | None = 100)[source]#
Parameters:
  • auth_handler (Union[OAuthHandler, OAuth2BearerHandler])

  • twitter_users (Sequence[str])

  • number_tweets (Optional[int])

async alazy_load() AsyncIterator[Document]#

A lazy loader for Documents.

Return type:

AsyncIterator[Document]

async aload() list[Document]#

Load data into Document objects.

Return type:

list[Document]

classmethod from_bearer_token(oauth2_bearer_token: str, twitter_users: Sequence[str], number_tweets: int | None = 100) TwitterTweetLoader[source]#

Create a TwitterTweetLoader from OAuth2 bearer token.

Parameters:
  • oauth2_bearer_token (str)

  • twitter_users (Sequence[str])

  • number_tweets (int | None)

Return type:

TwitterTweetLoader

classmethod from_secrets(access_token: str, access_token_secret: str, consumer_key: str, consumer_secret: str, twitter_users: Sequence[str], number_tweets: int | None = 100) TwitterTweetLoader[source]#

Create a TwitterTweetLoader from access tokens and secrets.

Parameters:
  • access_token (str)

  • access_token_secret (str)

  • consumer_key (str)

  • consumer_secret (str)

  • twitter_users (Sequence[str])

  • number_tweets (int | None)

Return type:

TwitterTweetLoader

lazy_load() Iterator[Document]#

A lazy loader for Documents.

Return type:

Iterator[Document]

load() List[Document][source]#

Load tweets.

Return type:

List[Document]

load_and_split(text_splitter: TextSplitter | None = None) list[Document]#

Load Documents and split into chunks. Chunks are returned as Documents.

Do not override this method. It should be considered to be deprecated!

Parameters:

text_splitter (Optional[TextSplitter]) – TextSplitter instance to use for splitting documents. Defaults to RecursiveCharacterTextSplitter.

Returns:

List of Documents.

Return type:

list[Document]

Examples using TwitterTweetLoader