neelsomani / parallel-python-twitter

A Twitter client to parallelize requests across multiple API keys
MIT License
6 stars 0 forks source link

GetFollowersID #4

Open yl4318 opened 4 years ago

yl4318 commented 4 years ago

Hi, I've read this code and found that a function is not defined:

class GetFollowerIDs(TwitterOp):
    """
    An operator to get the IDs of the users that are following the requested
    user.
    """
    def _invoke(self,
                user_id: Optional[int] = None,
                screen_name: Optional[str] = None,
                cursor: int = -1,
                max_count: Optional[int] = None) -> Tuple[int, int, List[int]]:
        """
        Return the users that are following the specified user.
        Parameters
        ----------
        user_id : Optional[int]
            The Twitter ID of the specified user
        screen_name : Optional[str]
            The Twitter handle of the specified user
        cursor : int
            Cursor to identify the page to pull, starting at -1
        max_count : Optional[int]
            The maximum number of friends to return. Defaults to 5000.
        """
        return self.api.GetFollowerIDsPaged(
            user_id=user_id,
            screen_name=screen_name,
            cursor=cursor,
            count=max_count
        )

I am not sure where is GetFollowerIDsPaged defined. Also I tried run get_followers and could not get a large list.

neelsomani commented 4 years ago

Hi @yl4318, the GetFollowerIDsPaged function is on the twitter.Api object (from the python-twitter package), which is passed to each TwitterOperator here. Did you install the requirements with pip install -r requirements.txt?

What is the error you're experiencing with parallel_client.get_followers? Just so we're on the same page, your code should look something like:

from parallel_twitter.parallel_client import oauth_dicts_to_apis, ParallelTwitterClient

TWITTER_API_CONSUMER_KEY = ...
TWITTER_API_CONSUMER_SECRET = ...
OAUTHS = [
    {
        'oauth_token': ...,
        'oauth_token_secret': ...
    },
    {
        'oauth_token': ...,
        'oauth_token_secret': ...
    },
    ...
]
apis = parallel_twitter.oauth_dicts_to_apis(
    oauth_dicts=OAUTHS,
    api_consumer_key=TWITTER_API_CONSUMER_KEY,
    api_consumer_secret=TWITTER_API_CONSUMER_SECRET
)
client = ParallelTwitterClient(apis=apis)
client.get_followers(user_id=...)