Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to get membership list #605

Merged
merged 2 commits into from
Mar 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion twarc/client2.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,49 @@ def _search(

log.info(f"No more results for search {query}.")

def list_memberships(
self,
id,
expansions=None,
list_fields=None,
max_results=None,
pagination_token=None,
user_field=None
):
"""
Function allows to get all the membership list from an specific user ID

Calls [GET /2/users/:id/list_memberships](https://developer.twitter.com/en/docs/twitter-api/lists/list-members/introduction)

Args:
expansions enum (owner_id): enable you to request additional data objects that relate to the originally returned List.
list.fields enum (created_at, follower_count, member_count, private, description, owner_id): This fields parameter enables you to select which specific List fields will deliver with each returned List objects.
max_results (int): The maximum number of results to be returned per page. This can be a number between 1 and 100.
pagination_token (string): Used to request the next page of results if all results weren't returned with the latest request, or to go back to the previous page of results.
user.fields( enum (created_at, description, entities, id, location, name, pinned_tweet_id, profile_image_url, protected, public_metrics, url, username, verified, withheld):
This fields parameter enables you to select which specific user fields will deliver with the users object. Specify the desired fields in a comma-separated list without spaces between commas and fields.
"""
user_id = self._ensure_user_id(id)

url = f"https://api.twitter.com/2/users/{user_id}/list_memberships"

params = self._prepare_params(
list_fields=list_fields,
max_results=max_results,
pagination_token=pagination_token,
user_field=user_field
)

if expansions:
params["expansions"] = "owner_id"

resp = self.get(url, params=params)
data = resp.json()

return data



def search_recent(
self,
query,
Expand Down Expand Up @@ -1220,7 +1263,7 @@ def get_paginated(self, *args, **kwargs):
Returns:
generator[dict]: A generator, dict for each page of results.
"""

resp = self.get(*args, **kwargs)
page = resp.json()

Expand Down