### Install GetStream Go SDK Source: https://getstream.io/activity-feeds/docs/go-golang/installation.md Use 'go get' to install the latest version of the GetStream Go SDK. Replace the version number with the latest available release from GitHub. ```bash go get github.com/GetStream/getstream-go/v4@v4.0.6 ``` -------------------------------- ### Read Feed with Options (Ruby) Source: https://getstream.io/activity-feeds/docs/dotnet-csharp/feeds.md This Ruby example shows how to read a feed and access its data. It includes setting up the client and making the get or create feed request. ```ruby require 'getstream_ruby' # Reading a feed feed = client.feed('user', 'john') request = GetStream::Generated::Models::GetOrCreateFeedRequest.new(user_id: 'john') feed_response = feed.get_or_create_feed(request) # Access feed data feed_data = feed_response.feed activities = feed_response.activities members = feed_response.members ``` -------------------------------- ### Install Node.js SDK Source: https://getstream.io/activity-feeds/docs/node/installation.md Install the SDK using npm or yarn. ```bash npm install @stream-io/node-sdk // or using yarn yarn add @stream-io/node-sdk ``` -------------------------------- ### Install React SDK with npm or yarn Source: https://getstream.io/activity-feeds/docs/react/installation.md Choose the appropriate command for your package manager to install the React SDK. ```bash npm install @stream-io/feeds-react-sdk # or using yarn yarn add @stream-io/feeds-react-sdk ``` -------------------------------- ### Install NuGet Package Source: https://getstream.io/activity-feeds/docs/dotnet-csharp/installation.md Use the NuGet Package Manager console to install the getstream-net package. ```bash NuGet\Install-Package getstream-net -Version 11.0.0 ``` -------------------------------- ### Get or Create Feed with View Override (Node.js) Source: https://getstream.io/activity-feeds/docs/flutter/feed-views.md This Node.js example demonstrates getting or creating a feed while overriding the default view with a specified ID and user ID. ```javascript feed.getOrCreate({ // Override the default view id view: "", user_id: "", }); ``` -------------------------------- ### Initialize Client with Manual Configuration Source: https://getstream.io/activity-feeds/docs/ruby/installation.md Create a client instance by manually providing your API key and secret. This method is useful for direct configuration. ```ruby require 'getstream_ruby' # Create client using manual configuration client = GetStreamRuby.manual( api_key: 'your_api_key', api_secret: 'your_api_secret' ) # Get the feeds client feeds_client = client.feeds # Your feeds operations here... ``` -------------------------------- ### Get or Create Feed with View Override (JavaScript) Source: https://getstream.io/activity-feeds/docs/flutter/feed-views.md Apply a specific feed view when getting or creating a feed using this JavaScript example. This overrides the default view. ```javascript feed.getOrCreate({ // Override the default view id view: "", }); ``` -------------------------------- ### Create, Update, and Delete Bookmark Folder in Go Source: https://getstream.io/activity-feeds/docs/android/bookmarks.md Provides a Go example for managing bookmark folders. This includes adding a bookmark to a new folder, updating the folder's name and custom data, and then deleting the folder. Error handling is included. ```go // Add a bookmark with a new folder addResp, err := client.Feeds().AddBookmark(context.Background(), activityID, &getstream.AddBookmarkRequest{ UserID: getstream.PtrTo("john"), NewFolder: &getstream.AddFolderRequest{ Name: "Breakfast recipes", Custom: map[string]any{"icon": "🍳"}, }, }) if err != nil { log.Fatal(err) } folderID := addResp.Data.Bookmark.Folder.ID // Update the folder updateResp, err := client.Feeds().UpdateBookmarkFolder(context.Background(), folderID, &getstream.UpdateBookmarkFolderRequest{ Name: getstream.PtrTo("Sweet Breakfast Recipes"), Custom: map[string]any{"icon": "🥞"}, }) if err != nil { log.Fatal(err) } // Delete the folder (and all bookmarks in it) _, err = client.Feeds().DeleteBookmarkFolder(context.Background(), updateResp.Data.BookmarkFolder.ID) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Get Next Page of Activities in Kotlin Source: https://getstream.io/activity-feeds/docs/android/feeds.md Retrieve the subsequent page of activities from a feed. This example assumes the feed object is already set up. ```kotlin val feed = client.feed( query = FeedQuery( group = "user", id = "john", activityLimit = 10 ) ) // Page 1 feed.getOrCreate() val activities = feed.state.activities // The flow emits the first 10 activities // Page 2 val page2Activities: Result> = feed.queryMoreActivities(limit = 10) val page1And2Activities = feed.state.activities ``` -------------------------------- ### Configure Client from .env File Source: https://getstream.io/activity-feeds/docs/ruby/installation.md Initialize the client by reading API credentials from a .env file in your project root. This simplifies credential management. ```ruby require 'getstream_ruby' # Initialize client from .env file client = GetStreamRuby.env # or client = GetStreamRuby.client # defaults to .env # Get the feeds client feeds_client = client.feeds ``` -------------------------------- ### Full Poll Update in Node.js Source: https://getstream.io/activity-feeds/docs/android/polls.md Update a poll using the Node.js client. This example includes a `user_id` parameter, which may be required depending on your setup. ```javascript await client.updatePoll({ id: "poll_456", name: "Where should we host our next company event?", options: [ { id: "option_789", text: "Amsterdam, The Netherlands", custom: { reason: "too expensive", }, }, { id: "option_123", text: "Boulder, CO", custom: { reason: "too far", }, }, ], user_id: "", }); ``` -------------------------------- ### Initiate User Data Export (Ruby) Source: https://getstream.io/activity-feeds/docs/dotnet-csharp/gdpr.md Starts the process of exporting user data. You will need to poll the task endpoint to get the status and result. ```ruby response = client.feeds.export_feed_user_data( GetStream::Generated::Models::ExportFeedUserDataRequest.new( user_id: user_to_export.id ) ) # You have to poll this endpoint task_response = client.get_task(response.data.task_id) puts task_response.data.status == 'completed' ``` -------------------------------- ### Add and Update Bookmarks in Go Source: https://getstream.io/activity-feeds/docs/android/bookmarks.md Provides examples for adding a bookmark to a new or existing folder, and updating a bookmark by adding custom data or relocating it to a different folder. Error handling is included for each operation. ```go // Adding a bookmark to a new folder _, err = client.Feeds().AddBookmark(context.Background(), activityID, &getstream.AddBookmarkRequest{ UserID: getstream.PtrTo("john"), }) if err != nil { log.Fatal("Error adding bookmark:", err) } // Adding to an existing folder _, err = client.Feeds().AddBookmark(context.Background(), activityID, &getstream.AddBookmarkRequest{ FolderID: getstream.PtrTo("folder_456"), UserID: getstream.PtrTo("john"), }) if err != nil { log.Fatal("Error adding bookmark to folder:", err) } // Update a bookmark (without a folder initially) - add custom data and move it to a new folder _, err = client.Feeds().UpdateBookmark(context.Background(), activityID, &getstream.UpdateBookmarkRequest{ FolderID: getstream.PtrTo("old folder id"), NewFolder: &getstream.AddFolderRequest{ Name: "New folder name", Custom: map[string]any{ "icon": "📂", }, }, Custom: map[string]any{ "color": "blue", }, UserID: getstream.PtrTo("john"), }) if err != nil { log.Fatal("Error updating bookmark:", err) } // Update a bookmark - move it from one existing folder to another existing folder _, err = client.Feeds().UpdateBookmark(context.Background(), activityID, &getstream.UpdateBookmarkRequest{ FolderID: getstream.PtrTo("old folder id"), NewFolderID: getstream.PtrTo("new folder id"), UserID: getstream.PtrTo("john"), }) if err != nil { log.Fatal("Error moving bookmark:", err) } ``` -------------------------------- ### Initiate User Data Export (Python) Source: https://getstream.io/activity-feeds/docs/dotnet-csharp/gdpr.md Starts the process of exporting user data. You will need to poll the task endpoint to get the status and result. ```python response = client.feeds.export_feed_user_data(user_id=user_to_export.id) # You have to poll this endpoint task_response = client.get_task(response.task_id) print(task_response.status == "completed") ``` -------------------------------- ### Create a User Feed in Go Source: https://getstream.io/activity-feeds/docs/android/feeds.md Go language example for creating feeds, showing both basic and advanced configurations with error handling. ```go // Example 1 response, err := feed.GetOrCreate(context.Background(), &getstream.GetOrCreateFeedRequest{ UserID: getstream.PtrTo("john"), }) if err != nil { log.Fatal("Error:", err) } log.Printf("Success: %+v\n", response) // Example 2 response2, err := feed.GetOrCreate(context.Background(), &getstream.GetOrCreateFeedRequest{ UserID: getstream.PtrTo("john"), Data: &getstream.FeedInput{ Description: getstream.PtrTo("My personal feed"), Name: getstream.PtrTo("John Hikes"), Visibility: getstream.PtrTo("public"), FilterTags: []string{"tech", "hiking", "cooking"}, }}) if err != nil { log.Fatal("Error creating advanced feed:", err) } log.Printf("Success: %+v\n", response2) ``` -------------------------------- ### Initiate User Data Export (C#) Source: https://getstream.io/activity-feeds/docs/dotnet-csharp/gdpr.md Starts the process of exporting user data. You will need to poll the task endpoint to get the status and result. ```csharp var response = await _feedsV3Client.ExportFeedUserDataAsync( new ExportFeedUserDataRequest { UserID = userToExport.ID } ); // You have to poll this endpoint var taskResponse = await _client.GetTaskAsync(response.TaskID); Console.WriteLine(taskResponse.Status == "completed"); ``` -------------------------------- ### Initiate User Data Export (PHP) Source: https://getstream.io/activity-feeds/docs/dotnet-csharp/gdpr.md Starts the process of exporting user data. You will need to poll the task endpoint to get the status and result. ```php $response = $feedsClient->exportFeedUserData( new GeneratedModels\ExportFeedUserDataRequest( userID: $userToExport->id ) ); // You have to poll this endpoint $taskResponse = $client->getTask($response->getData()->taskID); echo $taskResponse->getData()->status === 'completed'; ``` -------------------------------- ### Create Guest User Server-Side (Go) Source: https://getstream.io/activity-feeds/docs/android/user-management.md This Go snippet demonstrates creating a guest user on the server. It includes error handling and comments on returning the user data and access token. ```go response, err := client.CreateGuest(context.Background(), &getstream.CreateGuestRequest{ User: getstream.UserRequest{ ID: "tommaso", Name: getstream.PtrTo("Tommaso"), }, }) if err != nil { log.Fatal("Error creating guest:", err) } // Return response.Data.User and response.Data.AccessToken to your client ``` -------------------------------- ### Initiate User Data Export (Java) Source: https://getstream.io/activity-feeds/docs/dotnet-csharp/gdpr.md Starts the process of exporting user data. You will need to poll the task endpoint to get the status and result. ```java ExportFeedUserDataResponse response = feeds.exportFeedUserData( ExportFeedUserDataRequest.builder() .userID(userToExport.getId()) .build() ).execute().getData(); // You have to poll this endpoint var taskResponse = client.getTask(response.getTaskId()).execute().getData(); System.out.println("completed".equals(taskResponse.getStatus())); ``` -------------------------------- ### Create, Update, and Delete Bookmark Folder in Node.js Source: https://getstream.io/activity-feeds/docs/android/bookmarks.md Demonstrates managing bookmark folders with the Node.js SDK. The example covers adding a bookmark to a new folder, updating the folder's details, and then deleting the folder. ```js const bookmark = ( await client.feeds.addBookmark({ activity_id: activity.id, user_id: "", new_folder: { name: "Breakfast recipes", custom: { icon: "🍳", }, }, }) ).bookmark; const updatedFolder = ( await client.feeds.updateBookmarkFolder({ folder_id: bookmark.folder?.id, name: "Sweet Breakfast Recipes", custom: { icon: "🥞", }, }) ).bookmark_folder; await client.feeds.deleteBookmarkFolder({ folder_id: updatedFolder.id, }); ``` -------------------------------- ### Initiate User Data Export (Go) Source: https://getstream.io/activity-feeds/docs/dotnet-csharp/gdpr.md Starts the process of exporting user data. You will need to poll the task endpoint to get the status and result. ```go response, err := client.Feeds().ExportFeedUserData(context.Background(), &getstream.ExportFeedUserDataRequest{ UserID: userToExport.ID, }) if err != nil { log.Fatal(err) } // You have to poll this endpoint taskResponse, err := client.GetTask(context.Background(), response.Data.TaskID, &getstream.GetTaskRequest{}) if err != nil { log.Fatal(err) } fmt.Println(taskResponse.Data.Status == "completed") ``` -------------------------------- ### Initiate User Data Export (Node.js) Source: https://getstream.io/activity-feeds/docs/dotnet-csharp/gdpr.md Starts the process of exporting user data. You will need to poll the task endpoint to get the status and result. ```javascript const response = await client.feeds.exportFeedUserData({ user_id: userToExport.id, }); // You have to poll this endpoint const taskResponse = await client.getTask({ id: response.task_id }); console.log(taskResponse.status === "completed"); ``` -------------------------------- ### Create Guest User Server-Side (C#) Source: https://getstream.io/activity-feeds/docs/android/user-management.md This C# example demonstrates server-side guest user creation. The resulting user and access token should be sent to the client for authentication. ```csharp var request = new CreateGuestRequest { User = new UserRequest { ID = "tommaso", Name = "Tommaso" } }; var response = await _client.CreateGuestAsync(request); // Return response.User and response.AccessToken to your client ``` -------------------------------- ### Get Comments for an Activity with Threading (PHP) Source: https://getstream.io/activity-feeds/docs/php/comments.md Fetches comments for an activity, including threaded replies, with options for depth and sorting. This example uses the PHP SDK. ```PHP // Get comments for an activity with threading // activity id, object type, depth, sort, replies limit, limit, prev, next $response = $feedsClient->getComments('activity_123', 'activity', 3, 'best', 20, 20, '', ''); ``` -------------------------------- ### Multiple Selectors with Different Bonuses (Go) Source: https://getstream.io/activity-feeds/docs/dotnet-csharp/custom-ranking.md This Go example shows how to apply different score bonuses based on the 'selector_source' when multiple activity selectors are used. ```go _, err = client.Feeds().CreateFeedGroup(ctx, &getstream.CreateFeedGroupRequest{ ID: "timeline", ActivitySelectors: []getstream.ActivitySelectorConfig{ {Type: getstream.PtrTo("following")}, {Type: getstream.PtrTo("interest")}, {Type: getstream.PtrTo("popular"), MinPopularity: getstream.PtrTo(0)}, }, Ranking: &getstream.RankingConfig{ Type: getstream.PtrTo("expression"), Score: getstream.PtrTo(` (selector_source == "following" ? 10 : 0) + (selector_source == "interest" ? 5 : 0) + popularity `), Defaults: map[string]any{ "selector_source": "", }, }, }) ``` -------------------------------- ### Initialize and Use Stream Feeds in Ruby Source: https://getstream.io/activity-feeds/docs/android.md Demonstrates how to initialize the GetStream Ruby client, create or get a feed, and add an activity. ```ruby require 'getstream_ruby' # Initialize the client client = GetStreamRuby.manual( api_key: 'your_api_key', api_secret: 'your_api_secret' ) # Create a feed (or get its data if exists) feed_response = client.feeds.get_or_create_feed( 'user', 'john', GetStream::Generated::Models::GetOrCreateFeedRequest.new(user_id: 'john') ) # Add activity activity_request = GetStream::Generated::Models::AddActivityRequest.new( type: 'post', text: 'Hello, Stream Feeds!', user_id: 'john', feeds: ['user:john'] ) response = client.feeds.add_activity(activity_request) ``` -------------------------------- ### Get Comments from Activity (Python) Source: https://getstream.io/activity-feeds/docs/flutter/comments.md Access comments from the first activity in a feed response using the Python SDK. Includes an example for reading a single comment. ```python response = client.feeds.get_or_create_feed(...) comments = response["activities"][0]["comments"] ``` ```python # Reading a single comment comment = client.feeds.get_comment("123") ``` -------------------------------- ### Read Feed and Get Data (Java) Source: https://getstream.io/activity-feeds/docs/android/feeds.md Reads a feed and retrieves its state, including the feed ID, activities, and members. This example is specific to Java implementations. ```java testFeed = new Feed("user", testUserId, feeds); GetOrCreateFeedRequest feedRequest1 = GetOrCreateFeedRequest.builder().userID(testUserId).build(); GetOrCreateFeedResponse feedResponse1 = testFeed.getOrCreate(feedRequest1).getData(); testFeedId = feedResponse1.getFeed().getFeed(); ``` -------------------------------- ### Boost Following Activities with 2x Multiplier (Go) Source: https://getstream.io/activity-feeds/docs/dotnet-csharp/custom-ranking.md This Go example demonstrates a simple boost where activities from the 'following' selector receive a 2x multiplier in their score. ```go _, err := client.Feeds().CreateFeedGroup(ctx, &getstream.CreateFeedGroupRequest{ ID: "timeline", ActivitySelectors: []getstream.ActivitySelectorConfig{ {Type: getstream.PtrTo("following")}, {Type: getstream.PtrTo("popular"), MinPopularity: getstream.PtrTo(0)}, }, Ranking: &getstream.RankingConfig{ Type: getstream.PtrTo("expression"), Score: getstream.PtrTo(`selector_source == "following" ? popularity * 2 : popularity`), Defaults: map[string]any{ "selector_source": "", }, }, }) ``` -------------------------------- ### Get or Create Feed with External Ranking Boosts (PHP) Source: https://getstream.io/activity-feeds/docs/android/custom-ranking.md Example of creating or retrieving a feed and applying external ranking boosts based on stock symbols. ```php $feedResponse = $feedsClient->feed('timeline', 'john')->getOrCreateFeed( new GeneratedModels\GetOrCreateFeedRequest( externalRanking: (object) [ 'stock_boosts' => (object) [ 'apple' => 10.0, 'tesla' => 5.0, 'microsoft' => 2.0 ] ], userID: "john" ) ); // score = popularity + 10.0 + 5.0 = popularity + 15.0 (for activity with stocks: ['apple', 'tesla']) ``` -------------------------------- ### Initialize and Query Feeds Source: https://getstream.io/activity-feeds/docs/javascript/state.md Demonstrates how to initialize a single feed with optional WebSocket watching and how to query multiple feeds using a filter, also with optional WebSocket watching. ```javascript const feed = client.feed("user", "sara"); // Intialize feed state (will create feed, if it doesn't exist yet) // Provide the watch flag to receive state updates via WebSocket events await feed.getOrCreate({ watch: true }); // Query multiple feeds using a filter const feeds = client.queryFeeds({ filter: { // Your query }, // Provide the watch flag to receive state updates via WebSocket events watch: true, }); ``` -------------------------------- ### Get Comments for an Activity (Java) Source: https://getstream.io/activity-feeds/docs/android/comments.md Access comments from a feed response. Note: The Java SDK example focuses on accessing comments from an existing feed response. ```java GetOrCreateFeedResponse feedResponse = feeds.getOrCreateFeed(...).execute().getData(); var comments = feedResponse.getData().getActivities().get(0).getComments(); ``` -------------------------------- ### Manage Follow Requests in Kotlin Source: https://getstream.io/activity-feeds/docs/android/follows.md Shows how to set up feeds for follow requests, initiate a follow request, and then accept or reject it using the Kotlin SDK. ```kotlin // Sara needs to configure the feed with visibility = followers for enabling follow requests val saraFeed = saraClient.feed( query = FeedQuery( group = "user", id = "sara", data = FeedInputData(visibility = FeedVisibility.Followers) ) ) saraFeed.getOrCreate() // Adam requesting to follow the feed val adamTimeline = adamClient.feed(group = "timeline", id = "adam") adamTimeline.getOrCreate() val followRequest = adamTimeline.follow(saraFeed.fid) // user:sara println(followRequest.getOrNull()?.status) // FollowStatus.Pending // Sara accepting saraFeed.acceptFollow( sourceFid = adamTimeline.fid, // timeline:adam role = "feed_member" // optional ) // or rejecting the request saraFeed.rejectFollow(adamTimeline.fid) // timeline:adam ``` -------------------------------- ### Get Replies to a Specific Parent Comment (PHP) Source: https://getstream.io/activity-feeds/docs/php/comments.md Retrieves replies for a specific parent comment, allowing control over depth and sorting. This example uses the PHP SDK. ```PHP // Get replies of a specific parent comment // parent id, depth, sort, replies limit, limit, prev, next $response = $feedsClient->getCommentReplies('parent_123', 3, 'best', 20, 20, '', ''); ``` -------------------------------- ### Upload Image and File with Go SDK Source: https://getstream.io/activity-feeds/docs/flutter/file-uploads.md Provides examples for uploading an image and a regular file using the GetStream Go SDK. It covers creating temporary files, writing dummy data, and configuring upload requests with user information and specific sizes for images. The example also shows how to use the uploaded file URLs in activity attachments. ```go import ( "context" "os" "github.com/GetStream/getstream-go/v4" ) // Upload an image file tmpFile, err := os.CreateTemp("", "test-image-*.jpg") if err != nil { log.Fatal(err) } defer os.Remove(tmpFile.Name()) // Write some test image content (in real usage, use actual image data) tmpFile.WriteString("fake-image-data") tmpFile.Close() uploadReq := &getstream.UploadImageRequest{ File: getstream.PtrTo(tmpFile.Name()), UploadSizes: []getstream.ImageSize{ {Width: getstream.PtrTo(100), Height: getstream.PtrTo(100), Resize: getstream.PtrTo("scale"), Crop: getstream.PtrTo("center")}, }, User: &getstream.OnlyUserID{ ID: "john", }, } imageResponse, err := client.UploadImage(context.Background(), uploadReq) if err != nil { log.Fatal("Error uploading image:", err) } // Upload a regular file tmpFile2, err := os.CreateTemp("", "test-file-*.pdf") if err != nil { log.Fatal(err) } defer os.Remove(tmpFile2.Name()) tmpFile2.WriteString("fake-file-data") tmpFile2.Close() fileUploadReq := &getstream.UploadFileRequest{ File: getstream.PtrTo(tmpFile2.Name()), User: &getstream.OnlyUserID{ ID: "john", }, } fileResponse, err := client.UploadFile(context.Background(), fileUploadReq) if err != nil { log.Fatal("Error uploading file:", err) } // Use the uploaded file URLs in activity attachments feedsClient := client.Feeds() response, err := feedsClient.AddActivity(context.Background(), &getstream.AddActivityRequest{ Type: "post", Feeds: []string{"user:john"}, Text: getstream.PtrTo("Look at this amazing view of NYC!"), UserID: getstream.PtrTo("john"), Attachments: []getstream.Attachment{ { ImageUrl: imageResponse.Data.File, Type: getstream.PtrTo("image"), Title: getstream.PtrTo("NYC Skyline"), }, }, Custom: map[string]any{ "location": "New York City", "camera": "iPhone 15 Pro", }, }) if err != nil { log.Fatal("Error adding activity:", err) } ``` -------------------------------- ### Create and Get or Create Feed in Python Source: https://getstream.io/activity-feeds/docs/java/feeds.md Provides a Python example for creating feeds with user ID and filter tags. Assumes test_feed and test_feed_2 objects are pre-configured. ```python feed_response_1 = self.test_feed.get_or_create( user_id=self.test_user_id, filter_tags=["tech", "hiking", "cooking"] ) feed_response_2 = self.test_feed_2.get_or_create( user_id=self.test_user_id_2, filter_tags=["tech", "hiking", "cooking"] ) ``` -------------------------------- ### Get Comments from Activity (PHP) Source: https://getstream.io/activity-feeds/docs/flutter/comments.md Fetch comments for a specific activity using the PHP SDK. Includes examples for using the getComments endpoint and retrieving a single comment. ```php // Get comments for an activity // activity id, object type, depth, sort, replies limit, limit, prev, next $response = $feedsClient->getComments('activity_123', 'activity', 3, 'best', 10, 10, '', ''); echo json_encode($response->getData()); ``` ```php // Access comments from feed response $feedResponse = $feedsClient->feed('user', 'eric')->getOrCreateFeed( new GeneratedModels\GetOrCreateFeedRequest( userID: 'eric' ) ); $comments = $feedResponse->getData()->activities[0]->comments; ``` ```php // Reading a single comment $comment = $feedsClient->getComment('123'); ``` -------------------------------- ### Create, Update, and Delete Bookmark Folder in Java Source: https://getstream.io/activity-feeds/docs/android/bookmarks.md Shows how to manage bookmark folders using the Java SDK. This example covers adding a bookmark to a new folder, updating the folder's name and custom data, and then deleting the folder. ```java // Add a bookmark with a new folder AddBookmarkResponse addResponse = feeds.addBookmark(activityId, AddBookmarkRequest.builder() .userID(testUserId) .newFolder(AddFolderRequest.builder() .name("Breakfast recipes") .custom(Map.of("icon", "🍳")) .build()) .build()).execute().getData(); String folderId = addResponse.getBookmark().getFolder().getId(); // Update the folder UpdateBookmarkFolderResponse updateResponse = feeds.updateBookmarkFolder(folderId, UpdateBookmarkFolderRequest.builder() .name("Sweet Breakfast Recipes") .custom(Map.of("icon", "🥞")) .build()).execute().getData(); // Delete the folder (and all bookmarks in it) feeds.deleteBookmarkFolder(updateResponse.getBookmarkFolder().getId()).execute(); ``` -------------------------------- ### Follow a user or stock in Swift Source: https://getstream.io/activity-feeds/docs/javascript/follows.md Demonstrates how to follow a user or a stock using the Swift client. Includes an example of adding custom fields to the follow action. ```swift // Follow a user let timeline = client.feed(group: "timeline", id: "john") _ = try await timeline.follow(FeedId(group: "user", id: "tom")) // Follow a stock _ = try await timeline.follow(FeedId(group: "stock", id: "apple")) // Follow with more fields _ = try await timeline.follow( FeedId(group: "stock", id: "apple"), custom: ["reason": "investment"] ) ``` -------------------------------- ### Add and Update Bookmarks in Go Source: https://getstream.io/activity-feeds/docs/flutter/bookmarks.md Illustrates adding a new bookmark, adding to an existing folder, and updating bookmarks with custom data or folder modifications. ```go // Adding a bookmark to a new folder _, err = client.Feeds().AddBookmark(context.Background(), activityID, &getstream.AddBookmarkRequest{ UserID: getstream.PtrTo("john"), }) if err != nil { log.Fatal("Error adding bookmark:", err) } // Adding to an existing folder _, err = client.Feeds().AddBookmark(context.Background(), activityID, &getstream.AddBookmarkRequest{ FolderID: getstream.PtrTo("folder_456"), UserID: getstream.PtrTo("john"), }) if err != nil { log.Fatal("Error adding bookmark to folder:", err) } // Update a bookmark (without a folder initially) - add custom data and move it to a new folder _, err = client.Feeds().UpdateBookmark(context.Background(), activityID, &getstream.UpdateBookmarkRequest{ FolderID: getstream.PtrTo("old folder id"), NewFolder: &getstream.AddFolderRequest{ Name: "New folder name", Custom: map[string]any{ "icon": "📂", }, }, Custom: map[string]any{ "color": "blue", }, UserID: getstream.PtrTo("john"), }) if err != nil { log.Fatal("Error updating bookmark:", err) } // Update a bookmark - move it from one existing folder to another existing folder _, err = client.Feeds().UpdateBookmark(context.Background(), activityID, &getstream.UpdateBookmarkRequest{ FolderID: getstream.PtrTo("old folder id"), NewFolderID: getstream.PtrTo("new folder id"), UserID: getstream.PtrTo("john"), }) if err != nil { log.Fatal("Error moving bookmark:", err) } ``` -------------------------------- ### Get Comments for an Activity (Ruby) Source: https://getstream.io/activity-feeds/docs/android/comments.md Access comments from a feed response using the Ruby SDK. Note: This example focuses on accessing comments from an existing feed response. ```ruby feed_response = client.feeds.get_or_create_feed(...) comments = feed_response.data.activities[0].comments ``` -------------------------------- ### Get Comments for an Activity (Python) Source: https://getstream.io/activity-feeds/docs/android/comments.md Fetch comments associated with an activity using the Python SDK. Note: This example focuses on accessing comments from an existing feed response. ```python response = client.feeds.get_or_create_feed(...) comments = response["activities"][0]["comments"] ``` -------------------------------- ### Get or Create Follows with User Creation (Go) Source: https://getstream.io/activity-feeds/docs/android/follows.md Use this snippet to create multiple follows and automatically create any referenced users if they don't exist. The `create_users` flag must be set at the top level. ```go response, err := client.Feeds().GetOrCreateFollows(context.Background(), &getstream.GetOrCreateFollowsRequest{ CreateUsers: getstream.PtrTo(true), Follows: []getstream.FollowRequest{ { Source: "timeline:alice", Target: "user:bob", }, { Source: "timeline:alice", Target: "user:charlie", }, }, }) if err != nil { log.Fatal("Error creating follows with create_users:", err) } fmt.Printf("Created follows: %d\n", len(response.Data.Created)) ``` -------------------------------- ### Get Comments for an Activity (C#) Source: https://getstream.io/activity-feeds/docs/android/comments.md Access comments from a feed response using the C# SDK. Note: This example focuses on accessing comments from an existing feed response. ```csharp var feedResponse = await _feedsV3Client.GetOrCreateFeedAsync(...); var comments = feedResponse.Data.Activities[0].Comments; ``` -------------------------------- ### Query Users by Role (Go) Source: https://getstream.io/activity-feeds/docs/android/user-management.md A Go example for querying users, including setting filter conditions for roles, sort parameters, and handling potential errors. ```go response, err := client.QueryUsers(context.Background(), &getstream.QueryUsersRequest{ Payload: &getstream.QueryUsersPayload{ FilterConditions: map[string]any{ "role": "admin", }, Sort: []getstream.SortParamRequest{ { Field: getstream.PtrTo("created_at"), Direction: getstream.PtrTo(-1), }, }, Limit: getstream.PtrTo(10), Offset: getstream.PtrTo(0), }, }) if err != nil { log.Fatal("Error querying users:", err) } log.Printf("Found %d users\n", len(response.Data.Users)) ``` -------------------------------- ### Add and Update Bookmarks in Kotlin Source: https://getstream.io/activity-feeds/docs/android/bookmarks.md Provides examples for adding a bookmark, adding to a specific folder, updating a bookmark with custom data and a new folder, and moving a bookmark between folders using the Kotlin SDK. ```kotlin // Adding a bookmark to a new folder val bookmark: Result = feed.addBookmark(activityId = "activity_123") // Adding to an existing folder val bookmarkWithFolder: Result = feed.addBookmark( activityId = "activity_123", request = AddBookmarkRequest(folderId = "folder_456") ) // Update a bookmark (without a folder initially) - add custom data and move it to a new folder val updatedBookmark: Result = feed.updateBookmark( activityId = "activity_123", request = UpdateBookmarkRequest( custom = mapOf("color" to "blue"), newFolder = AddFolderRequest( custom = mapOf("icon" to "📁"), name = "New folder name" ) ) ) // Update a bookmark - move it from one existing folder to another existing folder val movedBookmark: Result = feed.updateBookmark( activityId = "activity_123", request = UpdateBookmarkRequest( folderId = "folder_456", newFolderId = "folder_789" ) ) ``` -------------------------------- ### Get or Create Feed (C#) Source: https://getstream.io/activity-feeds/docs/android/for-you-feed.md This C# example shows how to retrieve feed data using the GetOrCreateFeedAsync method. It requires the Feeds V3 client and a GetOrCreateFeedRequest object. ```csharp var feedResponse1 = await _feedsV3Client.GetOrCreateFeedAsync( FeedGroupID: "user", FeedID: _testFeedId, request: new GetOrCreateFeedRequest { UserID = _testUserId } ); var feedResponse2 = await _feedsV3Client.GetOrCreateFeedAsync( FeedGroupID: "user", FeedID: _testFeedId2, request: new GetOrCreateFeedRequest { UserID = _testUserId2 } ); ``` -------------------------------- ### Get Follow Suggestions in Java Source: https://getstream.io/activity-feeds/docs/android/follows.md Retrieve follow suggestions for a user using the Java SDK. This example shows how to construct the request, execute it, and iterate through the suggestions, printing details for each. ```Java // Get follow suggestions for a user GetFollowSuggestionsRequest request = GetFollowSuggestionsRequest.builder() .feedGroupId("user") .limit(10) .userId("john") .build(); GetFollowSuggestionsResponse response = feeds.getFollowSuggestions(request).execute().getData(); System.out.println("Algorithm used: " + response.getAlgorithmUsed()); System.out.println("Duration: " + response.getDuration()); for (FollowSuggestion suggestion : response.getSuggestions()) { System.out.println("Suggested feed: " + suggestion.getFid()); System.out.println("Name: " + suggestion.getName()); System.out.println("Description: " + suggestion.getDescription()); System.out.println("Follower count: " + suggestion.getFollowerCount()); System.out.println("Recommendation score: " + suggestion.getRecommendationScore()); System.out.println("Reason: " + suggestion.getReason()); System.out.println("Algorithm scores: " + suggestion.getAlgorithmScores()); } ``` -------------------------------- ### Query Users by Role (Python) Source: https://getstream.io/activity-feeds/docs/android/user-management.md A Python example for querying users, demonstrating how to set filter conditions for roles, sort parameters, and pagination. ```python from getstream.models import QueryUsersPayload, SortParamRequest response = self.client.query_users( payload=QueryUsersPayload( filter_conditions={ "role": "admin", }, sort=[ SortParamRequest(field="created_at", direction=-1) ], limit=10, offset=0, ) ) ``` -------------------------------- ### Configure Client from Environment Variables Source: https://getstream.io/activity-feeds/docs/ruby/installation.md Initialize the client by reading API credentials directly from environment variables. This is suitable for containerized or CI/CD environments. ```ruby require 'getstream_ruby' # Set environment variables (or export them in your shell) ENV['STREAM_API_KEY'] = 'your_api_key' ENV['STREAM_API_SECRET'] = 'your_api_secret' # Initialize client from environment variables client = GetStreamRuby.env_vars # Get the feeds client feeds_client = client.feeds ```