Skip to content

Instantly share code, notes, and snippets.

@edsu

edsu/errors.py

Last active Apr 29, 2021
Embed
What would you like to do?
This script surfs errors from the sample stream Twitter API. These come from trying to get user and tweet expansions for users and tweets that have been suspended, deleted or protected.
#!/usr/bin/env python3
# This script surfs errors from the sample stream Twitter API
# these come from trying to get user and tweet expansions for users and tweets
# that have been suspended, deleted or protected
import os
import twarc
import dotenv
dotenv.load_dotenv()
bearer_token = os.environ.get('BEARER_TOKEN')
twitter = twarc.client2.Twarc2(bearer_token=bearer_token)
for resp in twitter.sample():
for error in resp.get('errors', []):
print(error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment