Back to Llama Index

Twitter Reader

docs/examples/data_connectors/TwitterDemo.ipynb

0.14.211.3 KB
Original Source

<a href="https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/data_connectors/TwitterDemo.ipynb" target="_parent"></a>

Twitter Reader

python
%pip install llama-index-readers-twitter
python
import logging
import sys

logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))

If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.

python
!pip install llama-index
python
from llama_index.core import VectorStoreIndex
from llama_index.readers.twitter import TwitterTweetReader
from IPython.display import Markdown, display
import os
python
# create an app in https://developer.twitter.com/en/apps
BEARER_TOKEN = "<bearer_token>"
python
# create reader, specify twitter handles
reader = TwitterTweetReader(BEARER_TOKEN)
documents = reader.load_data(["@twitter_handle1"])
python
index = VectorStoreIndex.from_documents(documents)
python
# set Logging to DEBUG for more detailed outputs
query_engine = index.as_query_engine()
response = query_engine.query("<query_text>")
python
display(Markdown(f"<b>{response}</b>"))