0
votes

I am creating the application which need to track all tweets from user who registered to my application, i tried to track those with streaming API , there are public API, user API , and site API,

in those API it just have an option to follow the user ID by add the comma separated user ID https://dev.twitter.com/streaming/overview/request-parameters#follow but i think it is not flexible, if there are a new user registered , i need to rebuild the HTTP request , and also if there are so many users try to listen this stream and query will be so long, it will be

https://stream.twitter.com/1.1/statuses/filter.json?follow=[user1],[user2],[user3]........[userN],

i afraid the query wont fit, i just need a parameter to filter all user who registered in my application such as, for example. https://stream.twitter.com/1.1/statuses/filter.json?application=[applicationID] but i think twitter dev does not provide it

so, is there any way to filter stream by application ID?

2

2 Answers

0
votes

I didn't see anything like tracking by application id. If your query become too complex (too many follows/keywords), public streaming api will reject it, and you can't open more than 2 connections with user stream. So, last solution is using Site Stream, -> you can open as many user connections as you have users registered to your app.

BUT the docs says :

"Site Streams is currently in a closed beta. Applications are no longer being accepted."

Contact twitter to be sure

0
votes

Arstechnica has a very interesting article about it. Take a look at this code and the link in the end of this post

If you are using python pycurl will do the job. Its provides a way to execute a function for every little piece of data received.

import pycurl, json

STREAM_URL = "http://chirpstream.twitter.com/2b/user.json"

USER = "YOUR_USERNAME"
PASS = "XXXXXXXXX"

userlist = ['user1',...,'userN']

def on_receive(self, data):
    self.buffer += data
    if data.endswith("rn") and self.buffer.strip():
        content = json.loads(self.buffer)
        self.buffer = ""

        if "text" in content and content['user'] in userlist:
                #do stuff

conn = pycurl.Curl()
conn.setopt(pycurl.USERPWD, "%s:%s" % (USER, PASS))
conn.setopt(pycurl.URL, STREAM_URL)
conn.setopt(pycurl.WRITEFUNCTION, on_receive)
conn.perform()

You can find more information here Real time twitter stream api