Skip to content

Working with Activity Feed Posts

Post your first activity

To post an activity to global activity feed you can use code below:

  1. Create ActivityPostContent object:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    string buttonTitle = "Get extra life!";
    string buttonAction = "get-extra-life";
    Texture2D activityImage = ...;// load image here
    
    ActivityPostContent postContent = new ActivityPostContent.Builder()
        .WithText("Hello, this is my first post!")
        .WithButton(buttonTitle, buttonAction)
        .WithImage(activityImage)
        .Build();
    

    Recommended Image Size

    Recommended image resolution is 1024x768px. Bigger images will be downscaled.

  2. Post an activity to Global Feed:

    1
    2
    3
    4
    5
    6
    7
    GetSocial.PostActivityToGlobalFeed (postContent,
        post => {
            Debug.Log("Your activity was successfully posted!");
        },
        error => {
            Debug.LogWarning("Failed to post activity, error: " + error.Message);
        });
    

Custom Activity Feed

To post an activity to custom feed, just pass feed name as a parameter to PostActivityToFeed method:

1
GetSocial.PostActivityToFeed ("level-42", content, successAction, failureAction);

Action Buttons

Action button can be added to your activity or announcement. It is a simple, but very powerful part of Activity Feed functionality. See how to post activity with button:

  1. Create post content with Action Button:

    1
    2
    3
    4
    5
    6
    string buttonTitle = "Look now!";
    string buttonAction = "look-profille";
    ActivityPostContent postContent = new ActivityPostContent.Builder()
        .WithText("Look at my cool profile!")
        .WithButton(buttonTitle, buttonAction)
        .Build();
    
  2. Post to a selected feed:

    1
    GetSocial.PostActivityToGlobalFeed (postContent, successAction, failureAction);
    

In this case you will post as a user.
If you want to post as an App, use dashboard - simple activity, or post an Announcement.

Field Type Value
buttonTitle String A text that will be displayed on button
buttonAction String Your internal action, that you know how to deal with. Our SDK doesn’t know anything about your actions, we just attach them to buttons.

If you don’t use GetSocial UI, you should display and handle your button with own code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
if (post.HasButton) {
    // show button
    button.GetComponentInChildren<Text>().text = post.ButtonTitle;
    button.onClick.AddListener (() => {
        var action = post.ButtonAction;
        // handle your button click
        // processAction(action, post);
    });
} else {
    // hide button
}

If you’re using GetSocial UI, you life is easier, all you need is set ActionButtonListener:

1
2
3
4
5
6
GetSocialUi.CreateGlobalActivityFeedView ()
    .SetButtonActionListener ((action, post) => {
        // Handle your action on button click
        // processAction(action, post);
    })
    .Show ();

Example of your processAction method:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
void processAction(string action, ActivityPost post)
{
    switch (action) {
    case "look-profile":
        showUserProfile (post.Author);
        break;
    case "try-campaign-mode":
        startCampaignMode ();
        break;
    default:
        break;
    }
};

Post Activity With Mentions

To mention user in the Activity Feed post insert @12345678, where 12345678 is the GetSocial user Id you want to mention:

1
2
3
4
5
6
7
PublicUser user = ...;
string contentText = string.Format("Hello, @%s. How are you?", user.Id);
ActivityPostContent postContent = ActivityPostContent.CreateBuilder()
                .WithText(contentText)
                .Build();

GetSocial.PostActivityToGlobalFeed(postContent, onSuccess, onError);

To mention the application use "@app" in the post text:

1
2
3
4
5
ActivityPostContent postContent = ActivityPostContent.CreateBuilder()
                .WithText("Hey, @app. When new features will be available?")
                .Build();

GetSocial.PostActivityToGlobalFeed(postContent, onSuccess, onError);

On the backend, when activity is posted, @id is replaced with the display name of the user or app name.

To check if activity has any mentions in content, use post.Mentions method. Mention object contains id of user, start and end index of mention in content text, so you can handle interactions with mentions.

If you’re using GetSocial UI, to handle click on mention in Activity Feed, use MentionClickListener:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
GetSocialUi.CreateGlobalActivityFeedView()
    .SetMentionClickListener(mention => {
            if (mention == MentionShortcuts.App)
                // Handle click on the app mention
            } else {
                string userId = mention;
                // Handle click on the user mention
            }
    })
    .Show();

Post Activity With Tags

To post activity with tag, just insert #mytag - where mytag is a tag you want to post:

1
2
3
4
5
6
string contentText = "Like my #cat photo!";
ActivityPostContent postContent = ActivityPostContent.CreateBuilder()
                .WithText(contentText)
                .WithImage(myCatPhotoImage)
                .Build();
GetSocial.PostActivityToGlobalFeed(postContent, onSuccess, onFailure);

Tags may go one by one without spaces:

1
string contentText = "#get#social with your friends!"

The activity with text as above will have two tags #get and #social.

Warning

Tag should contain at least one letter, consist of letters, numbers and _, and be not longer than 80 symbols, otherwise it won’t be treated as tag on the backend side.

If you’re using GetSocial UI, to handle click on the tag use TagClickListener:

1
2
3
4
5
6
GetSocialUi.CreateGlobalActivityFeedView()
    .SetTagClickListener(tag => 
    {
        handleTagClick(tag);
    })
    .Show();

For example, on tag click you can open Activity Feed filtered by that tag using SetFilterByTags as described below.

Post from GetSocial UI

On the list of posts, there is an input to post something. Only text posts are supported from GetSocial UI, to post images or buttons from SDK, use code above.

List Activities

To get a list of posted activities in global feed:

1
2
3
4
5
6
7
8
9
ActivitiesQuery query = ActivitiesQuery.PostsForGlobalFeed ();
GetSocial.GetActivities (query,
    posts => {
        Debug.Log ("Successfully retrieved activities list");
        showActivities (posts);
    },
    error => {
        Debug.LogWarning ("Failed to get activities, error: " + error.Message);
    });

Pagination

ActivitiesQuery class supports pagination. By default, it retrieves first posts with limit=10.
Fox example, if you have a list of activities and want to get 15 older activities:

1
2
3
4
ActivityPost oldestActivity = activities.Last ();
ActivitiesQuery query = ActivitiesQuery.PostsForGlobalFeed ()
    .WithFilter (ActivitiesQuery.Filter.Older, oldestActivity.Id)
    .WithLimit (15);

In the same way you can get newer activities, using ActivitiesQuery.Filter.Newer:

1
2
3
4
ActivityPost newestActivity = activities.First ();
ActivitiesQuery query = ActivitiesQuery.PostsForGlobalFeed ()
    .WithFilter (ActivitiesQuery.Filter.Newer, newestActivity.Id)
    .WithLimit (15);

Filter By User

ActivitiesQuery class allows you to query activities posted by provided user. By default, it retrieves all activities.
For example, to get activities posted by current user:

1
2
3
4
string userId = GetSocial.User.Id;
ActivitiesQuery query = ActivitiesQuery
        .PostsForGlobalFeed()
        .FilterByUser(userId);

Friends Feed

You can ask to give you activities in feed, that were posted by you and your friends:

1
2
3
ActivitiesQuery query = ActivitiesQuery
        .PostsForGlobalFeed()
        .FriendsFeed(true);

Posts With Tags

You can filter all activities by tags, so you will have only activities that contain at least one tag from provided list:

1
2
3
ActivitiesQuery query = ActivitiesQuery
        .PostsForGlobalFeed()
        .WithTags("cat", "dog", "animal");

Open GetSocial Global Activity Feed View

GetSocialUI Library provides convenient way to show Activity Feed with all needed UI with a very little code execution:

1
2
3
4
5
6
bool wasShown = GetSocialUi.CreateGlobalActivityFeedView ()
    .SetButtonActionListener ((action, post) => {
        Debug.Log ("Button was pressed with action: " + action);
    })
    .Show ();
Debug.Log ("Get Social Activities UI was shown: " + wasShown);

You will see the similar view on the screen:


GetSocial Activity Feed View

If you want to customize Activity Feed view, see UI Customization.

Also, read more about GetSocial UI.

Custom Activity Feed

Custom activity feed is automatically created by SDK, so you don’t need to check does it exist or create it manually. Just use it:

  1. To open GetSocial Activity Feed View:

    1
    GetSocialUi.CreateActivityFeedView ("level-42").Show ();
    
  2. To create a query for custom feed activities:

    1
    ActivitiesQuery query = ActivitiesQuery.PostsForFeed ("level-42");
    

Feed name restrictions

Feed name could contain only alphanumeric symbols: letters [a-z], numbers [0-9], -, _, .; and should be not longer than 64 symbols.

User Avatar Click Listener

If you want to handle avatar click while using GetSocial UI, you can set AvatarClickListener when you’re creating view:

1
2
3
GetSocialUi.CreateGlobalActivityFeedView()
    .SetAvatarClickListener(user => handleAvatarClick(user))
    .Show();

For example, on avatar click you could:

  • Open user profile;
  • Suggest to add a user to friends;
  • Show some in-game information for a user;
  • Send a message for a user, etc.

Listener is not invoked on application avatar click

AvatarClickListener is invoked only by click on the user avatar, not application one. Reach us via Intercom or support@getsocial.im if you need this functionality.

Activity Feed View For User

You can specify an user ID to show activity feed with only his posts.
For example, to show activity feed of current user:

1
2
3
4
string userId = GetSocial.User.Id;
GetSocialUi.CreateGlobalActivityFeedView()
    .SetFilterByUser(userId)
    .Show();

Friends Feed View

You can show Friends Activity Feed, that contains activities posted by you and your friends. To do that, simply set showFriendsFeed to true:

1
2
3
GetSocialUi.CreateGlobalActivityFeedView()
    .SetShowFriendsFeed(true)
    .Show();

Read-only Activity Feed View

If you want to hide controls, that allows user to post, comment, like or dislike activities, you can use Read-only feed feature:

1
2
3
4
bool readOnlyFeed = true;
GetSocialUi.CreateGlobalActivityFeedView()
    .SetReadlOnly(readOnlyFeed)
    .Show();

Also, you can restrict user from doing some actions with UiActionListener.

Activity Feed View Filtered By Tags

You can show Activity Feed with activities that contain at least one tag from provided list:

1
2
3
GetSocialUi.CreateGlobalActivityFeedView()
    .SetFilterByTags("cat", "cats", "kitten")
    .Show();

Give us your feedback! Was this article helpful?

😀 🙁