Skip to content

Commit 9f4cc14

Browse files
committed
Update samples
1 parent eb00467 commit 9f4cc14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+431
-1216
lines changed

python/README.md

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,25 @@ export CONSUMER_SECRET='your_consumer_secret'
1919
## Examples
2020

2121
### Posts
22-
- posts/counts_full_archive.py
23-
- posts/counts_recent.py
24-
- posts/create_tweet.py
25-
- posts/delete_tweet.py
26-
- posts/full_archive_tweet_counts.py
27-
- posts/full-archive-search.py
28-
- posts/get_tweets_with_bearer_token.py
29-
- posts/get_tweets_with_user_context.py
30-
- posts/like_a_tweet.py
31-
- posts/liked_tweets.py
32-
- posts/liking_users.py
33-
- posts/lookup.py
34-
- posts/quote_tweets.py
35-
- posts/recent_search.py
36-
- posts/recent_tweet_counts.py
37-
- posts/reposted_by.py
38-
- posts/retweet_a_tweet.py
22+
- posts/create_post.py
23+
- posts/delete_post.py
24+
- posts/get_liked_posts.py
25+
- posts/get_liking_users.py
26+
- posts/get_post_counts_all.py
27+
- posts/get_post_counts_recent.py
28+
- posts/get_posts_by_ids.py
29+
- posts/get_quoted_posts.py
30+
- posts/like_post.py
31+
- posts/repost_post.py
3932
- posts/retweeted_by.py
40-
- posts/search_full_archive.py
33+
- posts/search_all.py
4134
- posts/search_recent.py
4235
- posts/undo_a_retweet.py
4336
- posts/unlike_a_tweet.py
4437

4538
### Users
46-
- users/block_a_user.py
47-
- users/blocked.py
48-
- users/followers_lookup.py
49-
- users/followers.py
5039
- users/following_lookup.py
51-
- users/following.py
40+
- users/get_followers.py
5241
- users/get_users_me_user_context.py
5342
- users/get_users_with_bearer_token.py
5443
- users/get_users_with_user_context.py
@@ -62,26 +51,24 @@ export CONSUMER_SECRET='your_consumer_secret'
6251
- users/unmute_a_user.py
6352

6453
### Timelines
65-
- timelines/home_timeline.py
54+
- timelines/get_mentions.py
55+
- timelines/get_posts.py
56+
- timelines/get_timeline.py
6657
- timelines/reverse-chron-home-timeline.py
67-
- timelines/user_mentions.py
68-
- timelines/user_posts.py
69-
- timelines/user_tweets.py
7058

7159
### Streams
7260
- streams/filtered_stream.py
7361
- streams/sampled_stream.py
7462

7563
### Lists
76-
- lists/add_member.py
77-
- lists/create_a_list.py
78-
- lists/delete_a_list.py
64+
- lists/add_list_member.py
65+
- lists/create_list.py
66+
- lists/delete_list.py
7967
- lists/follow_list.py
80-
- lists/list-followers-lookup.py
81-
- lists/list-lookup-by-id.py
82-
- lists/list-member-lookup.py
83-
- lists/List-Tweets.py
84-
- lists/lookup.py
68+
- lists/get_list_by_id.py
69+
- lists/get_list_followers.py
70+
- lists/get_list_members.py
71+
- lists/get_list_posts.py
8572
- lists/pin_list.py
8673
- lists/Pinned-List.py
8774
- lists/remove_member.py
@@ -122,6 +109,5 @@ export CONSUMER_SECRET='your_consumer_secret'
122109
- compliance/upload_ids.py
123110

124111
### Usage
125-
- usage/get_usage_tweets.py
126112
- usage/get_usage.py
127113

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def main():
5959
client = Client(access_token=access_token)
6060

6161
# Step 6: Create the list
62-
response = client.lists.create_list(body=payload)
62+
response = client.lists.create(body=payload)
6363

6464
print("Response code: 201")
6565
print(json.dumps(response.data, indent=4, sort_keys=True))
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ def main():
2727
for page in client.users.get_followed_lists(
2828
user_id,
2929
max_results=100,
30-
listfields=["created_at", "follower_count"]
30+
list_fields=["created_at", "follower_count"]
3131
):
32-
all_lists.extend(page.data)
33-
print(f"Fetched {len(page.data)} lists (total: {len(all_lists)})")
32+
# Access data attribute (model uses extra='allow' so data should be available)
33+
# Use getattr with fallback in case data field is missing from response
34+
page_data = getattr(page, 'data', []) or []
35+
all_lists.extend(page_data)
36+
print(f"Fetched {len(page_data)} lists (total: {len(all_lists)})")
3437

3538
print(f"\nTotal Followed Lists: {len(all_lists)}")
3639
print(json.dumps({"data": all_lists[:5]}, indent=4, sort_keys=True)) # Print first 5 as example
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@
1313
from xdk import Client
1414

1515
bearer_token = os.environ.get("BEARER_TOKEN")
16+
if not bearer_token:
17+
raise ValueError("BEARER_TOKEN environment variable is not set")
18+
1619
client = Client(bearer_token=bearer_token)
1720

1821
# You can replace the ID given with the List ID you wish to lookup.
1922
list_id = "list-id"
2023

2124
def main():
22-
# List fields are adjustable, options include:
23-
# created_at, description, owner_id,
24-
# private, follower_count, member_count,
25-
response = client.lists.get_list(
25+
# List fields are adjustable. Options include:
26+
# created_at, follower_count, member_count, private, description, owner_id
27+
response = client.lists.get_by_id(
2628
list_id,
27-
listfields=["created_at", "follower_count"]
29+
list_fields=["created_at", "follower_count", "member_count", "owner_id", "description"]
2830
)
2931

3032
print(json.dumps(response.data, indent=4, sort_keys=True))
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
from xdk import Client
1414

1515
bearer_token = os.environ.get("BEARER_TOKEN")
16+
if not bearer_token:
17+
raise ValueError("BEARER_TOKEN environment variable is not set")
18+
1619
client = Client(bearer_token=bearer_token)
1720

1821
# You can replace list-id with the List ID you wish to find followers of.
22+
# Note: Private lists require OAuth 2.0 user context authentication.
1923
list_id = "list-id"
2024

2125
def main():
@@ -28,13 +32,16 @@ def main():
2832
for page in client.lists.get_followers(
2933
list_id,
3034
max_results=100,
31-
userfields=["created_at", "description", "verified"]
35+
user_fields=["created_at", "description", "verified"]
3236
):
33-
all_users.extend(page.data)
34-
print(f"Fetched {len(page.data)} users (total: {len(all_users)})")
37+
# Access data attribute (model uses extra='allow' so data should be available)
38+
# Use getattr with fallback in case data field is missing from response
39+
page_data = getattr(page, 'data', []) or []
40+
all_users.extend(page_data)
41+
print(f"Fetched {len(page_data)} users (total: {len(all_users)})")
3542

3643
print(f"\nTotal Followers: {len(all_users)}")
3744
print(json.dumps({"data": all_users[:5]}, indent=4, sort_keys=True)) # Print first 5 as example
3845

3946
if __name__ == "__main__":
40-
main()
47+
main()
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ def main():
2828
for page in client.lists.get_members(
2929
list_id,
3030
max_results=100,
31-
userfields=["created_at", "description", "verified"]
31+
user_fields=["created_at", "description", "verified"]
3232
):
33-
all_users.extend(page.data)
34-
print(f"Fetched {len(page.data)} users (total: {len(all_users)})")
33+
# Access data attribute (model uses extra='allow' so data should be available)
34+
# Use getattr with fallback in case data field is missing from response
35+
page_data = getattr(page, 'data', []) or []
36+
all_users.extend(page_data)
37+
print(f"Fetched {len(page_data)} users (total: {len(all_users)})")
3538

3639
print(f"\nTotal Members: {len(all_users)}")
3740
print(json.dumps({"data": all_users[:5]}, indent=4, sort_keys=True)) # Print first 5 as example
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ def main():
2727
for page in client.users.get_list_memberships(
2828
user_id,
2929
max_results=100,
30-
listfields=["created_at", "follower_count"]
30+
list_fields=["created_at", "follower_count"]
3131
):
32-
all_lists.extend(page.data)
33-
print(f"Fetched {len(page.data)} lists (total: {len(all_lists)})")
32+
# Access data attribute (model uses extra='allow' so data should be available)
33+
# Use getattr with fallback in case data field is missing from response
34+
page_data = getattr(page, 'data', []) or []
35+
all_lists.extend(page_data)
36+
print(f"Fetched {len(page_data)} lists (total: {len(all_lists)})")
3437

3538
print(f"\nTotal List Memberships: {len(all_lists)}")
3639
print(json.dumps({"data": all_lists[:5]}, indent=4, sort_keys=True)) # Print first 5 as example
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ def main():
2828
# possibly_sensitive, promoted_metrics, public_metrics, referenced_tweets,
2929
# source, text, and withheld
3030
all_posts = []
31-
for page in client.lists.get_tweets(
31+
for page in client.lists.get_posts(
3232
list_id,
3333
max_results=100,
34-
tweetfields=["lang", "author_id"]
34+
tweet_fields=["lang", "author_id"]
3535
):
36-
all_posts.extend(page.data)
37-
print(f"Fetched {len(page.data)} posts (total: {len(all_posts)})")
36+
# Access data attribute (model uses extra='allow' so data should be available)
37+
# Use getattr with fallback in case data field is missing from response
38+
page_data = getattr(page, 'data', []) or []
39+
all_posts.extend(page_data)
40+
print(f"Fetched {len(page_data)} posts (total: {len(all_posts)})")
3841

3942
print(f"\nTotal Posts: {len(all_posts)}")
4043
print(json.dumps({"data": all_posts[:5]}, indent=4, sort_keys=True)) # Print first 5 as example

0 commit comments

Comments
 (0)