Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7996747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:46:59+00:00 2026-06-04T14:46:59+00:00

I am using java with the twitter search api to store tweets in mongoDB,

  • 0

I am using java with the twitter search api to store tweets in mongoDB, is there a way to store the json from the twitter api as is?

I am also considering using python, is there a way doing it in python?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:47:00+00:00Added an answer on June 4, 2026 at 2:47 pm

    I don’t know if you are still interested in an answer to this but from a purely python standing this is how I store the raw tweet json:

    import tweetstream # Needed For Twitter API Capture (Make sure using modified version with proxy support)
    import argparse    # Needed for taking cmd line input
    import gzip        # Needed for compressing output
    import json        # Needed for Data conversion for easier DB import
    import ast         # Also Needed for Data conversion
    
    collector = argparse.ArgumentParser(description='Collect a lot of Tweets')        # This line sets up the argument collector
    collector.add_argument('--username', dest='username', action="store")             # This line collects the Username
    collector.add_argument('--password', dest='password', action="store")             # This line collects the password
    collector.add_argument('--outputfilename', dest='outputfilename', action="store") # This line collects the output filename
    
    args = collector.parse_args()                                                     # Setup args to store cmd line arguments
    
    def printusername():                                                              # define the username argument
    
            print args.username
    
    def printpassword():                                                              # define the password argument
    
            print args.password
    
    def printoutputfilename():                                                        # define the output filename
    
            print args.outputfilename
    
    output=gzip.open(args.outputfilename, "a")                                        # Open the output file for GZIP writing
    
    with tweetstream.TweetStream(args.username, args.password) as stream:             # Open the Twitter Stream
        for tweet in stream:                                                          # For each tweet within the twitter stream
            line = str(tweet)                                                         # turn the tweet into a string
            line = ast.literal_eval(line)                                             # evaluate the python string (dictionary)
            line = json.dumps(line)                                                   # turn the python dictionary into valid JSON
            output.write(line)                                                        # write the line to the output file
            output.write("\n")  
    

    to run this just: “python myscript.py –username yourusername –password yourpassword –outputfilename yourpathandfilename”

    You’ll need tweetstream argparse gzip json and ast modules installed. All of which can be installed through pip or easy_install or most ubuntu/fedora package managers.

    The output file the script will create is a simple gzip compressed text file where each line is a new json string containing the complete tweet json object. Since the script runs until you hit your rate limit, it doesn’t close the gzip file with a proper EOF. However python doesn’t care so you can open it with another script, nor does 7zip or winrar.

    I hope that helps. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using twitter4j java library to make a twitter API search for given
I have a Java project where I am pulling tweets from twitter using the
Is there a way using Java to over-ride the browser authentication dialog box when
I am working with a java Twitter app (using Twitter4J api). I have created
Is it possible to tweet on twitter using java api without outh ? i.e
For parsing JSON like this twitter API users/show response I've been using Jackson and
I am trying to get the JSON data from a Twitter search request such
Any good source/website/inputs/sample to kickstart developing a twitter application using twitter API? Edit :
Is there a way to create an index and specify a custom analyzer using
when we use these apis •For Twitter: twitter4j •For Facebook: fb-java-api •For Linkedin: linkedin-j

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.