Interactive tutorial

Try the API

In this first example we're going to build a scalable newsfeed similar to Twitter's. A newsfeed shows the activities from the people you follow.

To run the examples you'll need an API key. Register to continue...

Get Your API Key Contact Us
// Initialize the client with your api key, no secret and your app id
var client = stream.connect('YOUR_API_KEY', null, 'SITE_ID');
// For the feed group 'user' and user id 'eric' get the feed
// The access token at the end is only needed for client side integrations
var ericFeed = client.feed('user', 'eric', 'token');
// Add the activity to the feed
ericFeed.addActivity({
  actor: 'eric', 
  tweet: 'Hello world', 
  verb: 'tweet', 
  object: 1
});
$ gem install "stream-ruby"
# Initialize the client with your api key and secret
require 'stream'
client = Stream::Client.new('YOUR_API_KEY', 'API_KEY_SECRET')
# For the feed group 'user' and user id 'eric' get the feed
ericFeed = client.feed('user', 'eric')
# Add the activity to the feed
activity_data = {:actor => 'eric', :verb => 'tweet', :object => 1, :tweet => 'Hello world'}
activity_response = ericFeed.add_activity(activity_data)
$ pip install stream-python
# Initialize the client with your api key and secret
import stream
client = stream.connect('YOUR_API_KEY', 'API_KEY_SECRET')
# For the feed group 'user' and user id 'eric' get the feed
eric_feed = client.feed('user', 'eric')
# Add the activity to the feed
eric_feed.add_activity({'actor': 'eric', 'verb': 'tweet', 'object': 1, 'tweet': 'Hello world'})
// See https://github.com/getstream/stream-php for install instructions

// Initialize the client with your api key and secret
$client = new GetStream\Stream\Client('YOUR_API_KEY', 'API_KEY_SECRET');

// For the feed group 'user' and user id 'eric' get the feed
$ericFeed = $client->feed('user', 'eric');

// Add the activity to the feed
$data = [
    "actor"=>"eric",
    "verb"=>"like",
    "object"=>"3",
    "tweet"=>"Hello world",
];

$ericFeed->addActivity($data);
>>> go get gopkg.in/GetStream/stream-go2.v1

// Initialize the client with your api key and secret.
// Error checks are removed for brevity, but always check err != nil
import "gopkg.in/GetStream/stream-go2.v1"

client, err := stream.NewClient(
    // API key
    "r32umt6d4zf9",
    // API secret
    "gve2u27qxzytm7a9988sq59692nrjwkv3brxsem7h7hs9gyz3puqqkcazbzjzvub",
    // API region
    stream.WithAPIRegion("us-east"),
)
// Get the feed object
ericFeed := client.FlatFeed("user", "eric")
// Add the activity to the feed
ericFeed.AddActivity(stream.Activity{
    Actor:  ericFeed.ID(),
    Verb:   "tweet",
    Object: "1",
    Extra: map[string]interface{}{
        "tweet": "Hello world",
    },
})

Success! The tweet now shows up on Eric's profile. Try replacing "Hello world" with a message of your own and run the JS again.

The activity you added has 4 fields: Actor, tweet, verb and object.

  • Actor is the user id of the person performing the activity.
  • Tweet is a custom field containing the message.
  • Verb is the type of activity the actor is engaging in.
  • Object is the id of the tweet object in your database.

These fields are based on the open activity stream spec. It allows you to represent many diverse activities. An activity could a be tweet, going for a run, adding a picture, listening to a song etc. In the next step you'll learn how to follow feeds.

Eric Baxter Profile
Jessica Le Timeline
Jule Beck Aggregated Timeline