2017 © Pedro Peláez
 

library stream

A PHP client for Stream (https://getstream.io)

image

get-stream/stream

A PHP client for Stream (https://getstream.io)

  • Thursday, May 3, 2018
  • by tbarbugli
  • Repository
  • 16 Watchers
  • 105 Stars
  • 256,073 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 30 Forks
  • 2 Open issues
  • 69 Versions
  • 4 % Grown

The README.md

Official PHP SDK for Stream Feeds

build Latest Stable Version, (*1)

, (*2)

Official PHP API client for Stream Feeds, a web service for building scalable newsfeeds and activity streams.
Explore the docs »

Laravel Feeds Library · Report Bug · Request Feature , (*3)

📝 About Stream

💡 Note: this is a library for the Feeds product. The Chat SDKs can be found here., (*4)

You can sign up for a Stream account at our Get Started page., (*5)

You can use this library to access Feeds API endpoints server-side., (*6)

For the client-side integrations (web and mobile) have a look at the JavaScript, iOS and Android SDK libraries (docs)., (*7)

💡 Note: there is also a higher level Laravel integration which hooks into the Eloquent ORM., (*8)

⚙️ Installation

$ composer require get-stream/stream

Composer will install our latest version automatically., (*9)

PHP compatibility

Current releases require PHP 8.0 or higher, and depends on Guzzle version ^7.5.0., (*10)

If you need to use the client with an old PHP or earlier versions of Guzzle, you can grab an earlier version of this package, for example:, (*11)

$ composer require get-stream/stream:"~5.0.0"

See the action for details of how it is built and tested against different PHP versions., (*12)

📚 Documentation

Our full documentation for this package is available at https://getstream.io/docs/php/., (*13)

✨ Getting started

First, signup here for a free account and grab your API key and secret., (*14)

Initiating a Client and a Feed object:, (*15)

// Instantiate a new client, find your API keys in the dashboard.
$client = new GetStream\Stream\Client('YOUR_API_KEY', 'YOUR_API_SECRET');

// Instantiate a feed object
$userFeed = $client->feed('user', '1');

// If you want, you can set a custom http handler
$handler = new \GuzzleHttp\HandlerStack();
$stack->push(Middleware::mapRequest(function (RequestInterface $r) {
    echo 'Sending request to Stream Feeds API: ' . $r->getUri() . PHP_EOL;
    return $r;
}));
$client->setCustomHttpHandler($handler);

By default, the Client will target the GetStream REST API at stream-io-api.com/api. If you want to change this for some reason you can set the STREAM_BASE_URL environment variable., (*16)

Activities in a feed:, (*17)

// Create a new activity
$data = [
    'actor' => '1',
    'verb' => 'like',
    'object' => '3',
    'foreign_id' => 'like:42',
];

$response = $userFeed->addActivity($data);

// The response will include Stream's internal ID:
// {"id": "e561...", "actor": "1", ...}

// Get the latest activities for this user's personal feed, based on who they are following.
$response = $userFeed->getActivities();

// Get activities directly by their ID or combination of foreign ID and time.
$response = $client->getActivitiesById(['74b9e88a-a684-4197-b30c-f5e568ef9ae2', '965f7ba5-8f1d-4fd1-a9ee-22d1a2832645']);
$response = $client->getActivitiesByForeignId(['fid:123', '2006-01-02T15:04:05.000000000'], ['fid:456', '2006-01-02T16:05:06.000000000']);

// The response will be the json decoded API response.
// {"duration": 45ms, "next": "/api/v1.0/feed/...", "results": [...]}

// Remove an activity by its ID
$userFeed->removeActivity('e561de8f-00f1-11e4-b400-0cc47a024be0');

// To remove activities by their foreign_id, set the "foreign id" flag to true.
$userFeed->removeActivity('like:42', true);

Following/follower relations of a feed:, (*18)

// When user 1 starts following user 37's activities
$userFeed->follow('user', '37');

// When user 1 stops following user 37's activities
$userFeed->unfollow('user', '37');

// Retrieve followers of a feed
$userFeed->followers();

// Retrieve feeds followed by $userFeed
$userFeed->following();

Advanced activity operations:, (*19)

// Create a bit more complex activity with custom fields
$data = [
    'actor' => 1,
    'verb' => 'run',
    'object' => 1,
    'foreign_id' => 'run:42',

    // Custom fields:
    'course' => [
        'name'=> 'Golden Gate park',
        'distance'=> 10,
    ],
    'participants' => ['Thierry', 'Tommaso'],
    'started_at' => new DateTime('now', new DateTimeZone('Pacific/Nauru'),
];

// Add an activity and push it to other feeds too using the `to` field
$data = [
    'actor' => '1',
    'verb' => 'like',
    'object' => '3',
    'to' => [
        'user:44',
        'user:45',
    ],
];

$userFeed->addActivity($data);

// Batch adding activities
$activities = [
    ['actor' => '1', 'verb' => 'tweet', 'object' => '1'],
    ['actor' => '2', 'verb' => 'like', 'object' => '3'],
];

$userFeed->addActivities($activities);

Advanced batching:, (*20)

// Batch operations (batch activity add, batch follow)
$batcher = $client->batcher();

// Add one activity to many feeds
$activity = ['actor' => '1', 'verb' => 'tweet', 'object' => '1'];
$feeds = ['user:1', 'user:2'];

$batcher->addToMany($activity, $feeds);

// Create many follow relations
$follows = [
    ['source' => 'user:b1', 'target' => 'user:b2'],
    ['source' => 'user:b1', 'target' => 'user:b3'],
];

$batcher->followMany($follows);

Generating tokens for client-side usage:, (*21)

// Generating a user token
$userToken = $client->createUserSessionToken("the-user-id");

RateLimits:, (*22)

If your app hits a ratelimit, a StreamFeedException is thrown. You can get additional info by catching the exception and calling the following methods:, (*23)


try { $client->updateActivity($activity); }catch(StreamFeedException $e){ $limit = $e->getRateLimitLimit(); $remaining = $e->getRateLimitRemaining(); $reset = $e->getRateLimitReset(); // a unix timestamp }

Reactions:, (*24)

The reactions module has the following methods., (*25)

- add(string $kind, string $activityId, string $userId, array $data=null, array $targetFeeds=null)
- addChild(string $kind, string $parentId, string $userId, array $data=null, array $targetFeeds=null)
- delete(string $reactionId)
- filter(string $lookupField, string $lookupValue, string $kind=null, array $params=null)
- get(string $reactionId)
- update(string $reactionId, array $data=null, array $targetFeeds=null)

Also see documention on the reactions endpoint, (*26)


$reaction = $client->reactions()->add('like', $activity_id, 'bob'); $bob_likes = $client->reactions()->filter('user_id', 'bob', 'like'); $client->reactions()->delete($reaction['id']);

Users:, (*27)

The users module has the following methods., (*28)

- add(string $userId, array $data=null, bool $getOrCreate=false)
- createReference(string $userId)
- delete(string $userId)
- get(string $userId)
- update(string $userId, array $data=null)

Also see documention on the users endpoint, (*29)


$user = $client->users()->add('42'); $user = $client->users()->update('42', array('name' => 'Arthur Dent'); $client->users()->delete('42');

Again, our full documentation with all options and methods, is available at https://getstream.io/docs/php/., (*30)

☯️ Framework integration

Laravel

There's a higher level integration with Laravel called get-stream/stream-laravel. The stream-laravel integration helps you to hook into the Laravel's Eloquent ORM to sync data to Stream., (*31)

✍️ Contributing

Project is licensed under the BSD 3-Clause., (*32)

We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our Contributor License Agreement (CLA) first. See our license file for more details., (*33)

🧑‍💻 We are hiring!

We've recently closed a $38 million Series B funding round and we keep actively growing. Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world., (*34)

Check out our current openings and apply via Stream's website., (*35)

The Versions

03/05 2018

dev-master

9999999-dev https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD BSD-3-Clause

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

03/05 2018

dev-unfollow-many

dev-unfollow-many https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

16/04 2018

2.7.0

2.7.0.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

16/04 2018

dev-feature/gzip

dev-feature/gzip https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

13/04 2018

dev-feature/personalization

dev-feature/personalization https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

26/02 2018

2.6.0

2.6.0.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

26/02 2018

dev-fix/99designs

dev-fix/99designs https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

22/02 2018

2.5.2

2.5.2.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

22/02 2018

dev-fix/automatic-client-version

dev-fix/automatic-client-version https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD BSD-3-Clause

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

14/11 2017

dev-fix/cs

dev-fix/cs https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

02/11 2017

2.5.1

2.5.1.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

26/10 2017

dev-fix/tests

dev-fix/tests https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

26/10 2017

dev-document-env-variable

dev-document-env-variable https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

17/10 2017

2.5.0

2.5.0.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

03/10 2017

2.4.2

2.4.2.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

29/09 2017

dev-fix/update-activities-empty-array

dev-fix/update-activities-empty-array https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

26/09 2017

2.4.1

2.4.1.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

22/09 2017

dev-fix/readme

dev-fix/readme https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

21/09 2017

dev-fix/code-coverage

dev-fix/code-coverage https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

21/09 2017

dev-fix/test-suite

dev-fix/test-suite https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

20/09 2017

dev-fix/guzzle-request-options

dev-fix/guzzle-request-options https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

31/08 2017

2.4.0

2.4.0.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

20/03 2017

2.3.0

2.3.0.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

20/03 2017

dev-follow_many_limit

dev-follow_many_limit https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

15/03 2017

dev-maint-update-license-copyright-2017

dev-maint-update-license-copyright-2017 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

28/02 2017

dev-sni

dev-sni https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

27/02 2017

dev-feature/fixed-tests

dev-feature/fixed-tests https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

17/10 2016

dev-qa-fix

dev-qa-fix https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

13/10 2016

2.2.9

2.2.9.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

13/10 2016

dev-oss-cleanup

dev-oss-cleanup https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

29/06 2016

2.2.8

2.2.8.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

26/04 2016

2.2.7

2.2.7.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

16/03 2016

2.2.6

2.2.6.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

22/02 2016

2.2.5

2.2.5.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

22/02 2016

2.2.4

2.2.4.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

27/01 2016

2.2.3

2.2.3.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

07/01 2016

dev-fix-issue-11

dev-fix-issue-11 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

19/08 2015

2.2.2

2.2.2.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

19/08 2015

2.2.1

2.2.1.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

18/08 2015

2.2.0

2.2.0.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

18/08 2015

dev-guzzle-six

dev-guzzle-six https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

16/06 2015

2.1.4

2.1.4.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

11/06 2015

2.1.3

2.1.3.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

31/05 2015

2.1.2

2.1.2.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

16/03 2015

2.1.1

2.1.1.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

19/12 2014

2.1.0

2.1.0.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

09/12 2014

2.0.4

2.0.4.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

25/11 2014

2.0.3

2.0.3.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

14/11 2014

2.0.2

2.0.2.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

12/11 2014

2.0.1

2.0.1.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

11/11 2014

dev-new

dev-new https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

11/11 2014

2.0.0

2.0.0.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

15/10 2014

1.3.8

1.3.8.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

15/10 2014

1.3.7

1.3.7.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

01/10 2014

1.3.6

1.3.6.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

08/09 2014

1.3.5

1.3.5.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

08/09 2014

1.3.4

1.3.4.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

25/08 2014

1.3.3

1.3.3.0 https://getstream.io

A PHP client for Stream (https://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

25/08 2014

1.3.2

1.3.2.0 http://getfeedly.io

A PHP client for Stream (http://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

15/08 2014

1.3.1

1.3.1.0 http://getfeedly.io

A PHP client for Stream (http://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

12/08 2014

1.3.0

1.3.0.0 http://getfeedly.io

A PHP client for Stream (http://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

05/08 2014

1.0.5

1.0.5.0 http://getfeedly.io

A PHP client for Stream (http://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

03/08 2014

1.2.0

1.2.0.0 http://getfeedly.io

A PHP client for Stream (http://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

15/07 2014

1.1

1.1.0.0 http://getfeedly.io

A PHP client for Stream (http://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

02/07 2014

1.0.4

1.0.4.0 http://getfeedly.io

A PHP client for Stream (http://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

24/06 2014

1.0.3

1.0.3.0 http://getfeedly.io

A PHP client for Stream (http://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

19/06 2014

1.0.2

1.0.2.0 http://getfeedly.io

A PHP client for Stream (http://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

19/06 2014

1.0.1

1.0.1.0 http://getfeedly.io

A PHP client for Stream (http://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly

19/05 2014

1.0.0

1.0.0.0 http://getfeedly.io

A PHP client for Stream (http://getstream.io)

  Sources   Download

BSD

The Requires

 

The Development Requires

by Tommaso Barbugli

stream newsfeed feedly