// add the stream-net to your project:
// https://www.nuget.org/packages/stream-net/
<PackageReference Include="stream-net" Version="6.5.3" />Getting Started
Learn How Easy It Can Be To Build Scalable Newsfeeds and Activity Streams
Stream has official clients for JS/Node, Ruby, Python, PHP, Go, Java and C#/.NET.
Setup
Let's get set up! First, install the client as specified below:
All source code can be found on GitHub.
To instantiate the client you need an API key and secret . You can find the key and secret on the dashboard. The examples below already include your key and secret.
// Create a client, find your API keys here https://getstream.io/dashboard/
// optionally set the region of your app and default timeout
Client = new StreamClient(
Environment.GetEnvironmentVariable("STREAM_API_KEY"),
Environment.GetEnvironmentVariable("STREAM_API_SECRET"),
new StreamClientOptions
{
Location = StreamApiLocation.USEast,
Timeout = 16000,
});If you want to use Stream on your mobile or web application, you need to generate a token server-side that the client can use to authenticate as a user of your application.
Generate User Token Server-Side
This code generates the token for one of your users; a common place to do this is at signup or login. The token is then passed to the frontend.
var token = client.CreateUserToken("the-user-id");Use Stream API client-side
const stream = require("getstream");
// Instantiate new client with a user token
const client = stream.connect(
"{{ api_key }}",
"{{ feed_token }}",
"{{ app_id }}",
);
// OR
import stream from "getstream";
const client = stream.connect(
"{{ api_key }}",
"{{ feed_token }}",
"{{ app_id }}",
);More details about authentication can be found in the REST docs
Quick Start
The quick start below shows you how to build a scalable social network. It highlights the most common API calls:
var chrisFeed = client.Feed("user", "chris");
// Add an Activity; message is a custom field - tip: you can add unlimited custom fields!
var activity = new Activity("chris", "add", "picture:10")
{
ForeignId = "picture:10"
};
activity.SetData("message", "Beautiful bird!");
await chrisFeed.AddActivityAsync(activity);
// Create a following relationship between Jack's "timeline" feed and Chris' "user" feed:
jackTimeline = client.Feed("timeline", "jack");
jackTimeline.FollowFeed("user", "chris");
// Read Jack's timeline and Chris' post appears in the feed:
var activities = await jackTimeline.GetActivitiesAsync(0, 10);
// Remove the activity by referencing the foreign_id you provided:
await chrisFeed.RemoveActivityAsync("picture:10", true);
// for more exaxmples check:
// https://github.com/GetStream/stream-net/blob/master/README.mdThat was a good deal of information at once. The getting started docs provide a more detailed and interactive explanation.