References
When you add a user or a collection object to an activity, Stream stores the unique reference and replaces it at read time. In some complex cases, you need to be able to generate a reference to an existing object and embed that inside of an activity.
// First create a collection entry with upsert api
client.collections().upsert("food", new CollectionData().set("name", "Cheese Burger")).join();
// Then create a user
client.user("john-doe").create(new Data()
.set("name", "John Doe")
.set("occupation", "Software Engineer")
.set("gender", "male")).join();
// Since we know their IDs we can create references to both without reading from APIs
String cheeseBurgerRef = createCollectionReference("food", "cheese-burger");
String johnDoeRef = createUserReference("john-doe");
client.flatFeed("user", "john").addActivity(Activity.builder()
.actor(johnDoeRef)
.verb("eat")
.object(cheeseBurgerRef)
.build()).join();Info:
If you are using the APIs on web / mobile (see auth section) you must set activity.actor to the reference of the current user or otherwise you will get a permission error (see examples above).