-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
126 lines (115 loc) · 5.27 KB
/
Program.cs
File metadata and controls
126 lines (115 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Threading.Tasks;
using GetStream;
using GetStream.Models;
using System.Collections.Generic;
namespace GetStream.Example
{
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("=== GetStream .NET SDK Complete Example ===\n");
Console.WriteLine("🔧 Initializing clients...");
// Clients automatically load credentials from .env file or environment variables
var feedsClient = new FeedsV3Client();
var client = new StreamClient();
Console.WriteLine("✅ Successfully initialized clients with automatic credential loading!");
var feed = feedsClient.Feed("user", "example-feed-2");
try
{
// 0. Create a user
Console.WriteLine("0. Creating user...");
var userRes = await client.UpdateUsersAsync(
new UpdateUsersRequest
{
Users = new Dictionary<string, UserRequest>
{
{
"okabe", // Changed from "sara" to match the user ID
new UserRequest
{
ID = "okabe",
Name = "Okabe",
Custom = new Dictionary<string, object>
{
{ "occupation", "Scientist" }
}
}
}
}
}
);
// 1. Create a feed
Console.WriteLine("1. Creating feed...");
var feedRes = await feed.GetOrCreateFeedAsync(
request: new GetOrCreateFeedRequest
{
UserID = userRes.Data?.Users.FirstOrDefault().Value.ID
}
);
Console.WriteLine($"✅ Feed created successfully: {feedRes.Data.Feed.Feed}\n");
// 2. Add an activity to the feed
Console.WriteLine("2. Adding activity to feed...");
var addActivityResponse = await feedsClient.AddActivityAsync(
new AddActivityRequest
{
Type = "post",
Feeds = new List<string> { feedRes.Data.Feed.Feed },
Text = "Hello from .NET SDK! This is my first activity.",
UserID = "okabe"
}
);
Console.WriteLine("✅ Activity added successfully!");
Console.WriteLine($" Activity ID: {addActivityResponse.Data?.Activity?.ID}");
Console.WriteLine($" Activity Type: {addActivityResponse.Data?.Activity?.Type}");
Console.WriteLine($" Activity Text: {addActivityResponse.Data?.Activity?.Text}\n");
// 3. Add a comment to the activity
Console.WriteLine("3. Adding comment to activity...");
var addCommentResponse = await feedsClient.AddActivityAsync(
new AddActivityRequest
{
Type = "comment",
Feeds = new List<string> { feedRes.Data.Feed.Feed },
Text = "This is a great post!",
UserID = "okabe"
}
);
Console.WriteLine("✅ Comment added successfully!");
Console.WriteLine($" Comment ID: {addCommentResponse.Data?.Activity?.ID}");
Console.WriteLine($" Comment Text: {addCommentResponse.Data?.Activity?.Text}\n");
// 4. Fetch feed activities
Console.WriteLine("4. Fetching feed activities...");
var queryResponse = await feedsClient.QueryActivitiesAsync(
new QueryActivitiesRequest
{
Limit = 10
}
);
Console.WriteLine("✅ Feed fetched successfully!");
Console.WriteLine($" Total activities: {queryResponse.Data?.Activities?.Count}");
foreach (var activity in queryResponse.Data?.Activities ?? new List<ActivityResponse>())
{
Console.WriteLine($" - Activity: {activity.Type} - {activity.Text}");
}
Console.WriteLine();
// 5. Get the feed we created
Console.WriteLine("5. Getting the feed we created...");
var getResponse = await feed.GetOrCreateFeedAsync(
request: new GetOrCreateFeedRequest
{
UserID = "okabe"
}
);
Console.WriteLine("✅ Feed retrieved successfully!");
Console.WriteLine($" Feed Data: {getResponse.Data}\n");
Console.WriteLine("=== Example completed ===");
}
catch (Exception ex)
{
Console.WriteLine($"❌ Error: {ex.Message}");
throw;
}
}
}
}