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:

// Add the following dependency and repository to your pom.xml file

<dependency>
  <groupId>io.getstream.client</groupId>
  <artifactId>stream-java</artifactId>
  <version>3.0.0</version>
</dependency>

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.

// import io.getstream.client.Client;

Client client = Client.builder(
 '{{ api_key }}',
 '{{ api_secret }}'
 ).build();

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.

Token userToken = client.frontendToken("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:

FlatFeed chris = client.flatFeed("user", "chris");
// Add an Activity; message is a custom field - tip: you can add unlimited custom fields!
chris.addActivity(Activity.builder()
    .actor("chris")
    .verb("add")
    .object("picture:10")
    .foreignID("picture:10")
    .extraField("message", "Beautiful bird!")
    .build());

// Create a following relationship between Jack's "timeline" feed and Chris' "user" feed:
FlatFeed jack = client.flatFeed("timeline", "jack");
ack.follow(chris).join();

// Read Jack's timeline and Chris' post appears in the feed:
List<Activity> response = jack.getActivities(new Pagination().limit(10)).join();
for (Activity activity : response) {
    // ...
}

// Remove an Activity by referencing it's foreign_id
chris.removeActivityByForeignID("picture:10").join();

That was a good deal of information at once. The getting started docs provide a more detailed and interactive explanation.