Skip to content

Share Content

Sharing an activity

Create invite content from the activity

val activity: GetSocialActivity // activity to share

val inviteContent = InviteContent()
// set text
inviteContent.text = activity.text
// set image
inviteContent.mediaAttachment = activity.attachments.first()
// set activity id
val activityData = HashMap<String, Any>();
activityData["ACTIVITY_ID"] = activity.id
inviteContent.linkParams = activityData
let activity: Activity //  activity to share

let inviteContent = InviteContent()
// set text
inviteContent.text = activity.text
// set image
inviteContent.mediaAttachment = activity?.mediaAttachments.first
// set activity id
inviteContent.linkParams = ["ACTIVITY_ID": (activity!.id as NSString)]
var inviteContent = InviteContent();
// set text
inviteContent.text = activity.text;
// set image
inviteContent.mediaAttachment = activity.attachments.first;
// set activity id
inviteContent.linkParams = new Map();
inviteContent.linkParams['ACTIVITY_ID'] = activity.id;
let activity: Activity; //  activity to share

let inviteContent = new InviteContent();
// set text
inviteContent.text = activity.text
// set image
inviteContent.mediaAttachment = activity.mediaAttachments[0];
// set activity id
inviteContent.linkParams.ACTIVITY_ID = activity.id;
let activity: Activity; //  activity to share

let inviteContent = new GetSocialSDK.InviteContent({
    // set text
    text: activity.text,
    // E-mail subject
    subject: 'Subject',
    // Twitter account
    twitterVia: 'GetSocial_now',
    // set activity id
    linkParams: {
        ACTIVITY_ID: activity.id
    }
});

Send the invite

// send the invite via email
Invites.send(inviteContent, InviteChannelIds.EMAIL, {
    Log.d("Communities", "Invite sent")
}, {
    Log.d("Communities", "Sending invite cancelled")
}, { error ->
    Log.d("Communities", "Failed to send invite: $error")
})
// send the invite via email
Invites.send(inviteContent, onChannel: InviteChannelIds.email, success: {
    print("Invite sent")
}, cancel: {
    print("Sending invite cancelled")
}, failure: { error in
    print("Failed to send invite: \(error)")
})
// send the invite via email
Invites.send(inviteContent, InviteChannelIds.email,
    () => print('Invite sent'),
    () => print('Invite cancelled'),
    (error) => print('Failed to send invite, error: $error'));
// send the invite via email
Invites.send(
    inviteContent,
    'email'
    () => console.log('Invite sent'),
    () => console.log('Invite cancelled'),
    (error) => console.error('Failed to send invite, error: ', error)
);
// send the invite via email
GetSocialSDK.Invites.send(inviteContent, 'email')
    .then(
        () => console.log('Invite sent'),
        (error) => console.error('Failed to send invite, error: ', error)
    );
);

Receive the invite

Invites.setReferralDataListener({ data ->
    // get activity data
    val activityId = data.linkParams["ACTIVITY_ID"]
})
Invites.setOnReferralDataReceivedListener({ data in
    let activityId = data.linkParams["ACTIVITY_ID"]
})
Invites.setOnReferralDataReceivedListener((ReferralData referralData) => {
   var activityId = data.linkParams['ACTIVITY_ID']
});
Invites.setOnReferralDataReceivedListener((referralData) => {
    console.log(`Activity ID: ${referralData.referralLinkParams.ACTIVITY_ID}`);
});

Referral data on Web SDK

The Web SDK doesn’t provide a way to register a listener but it does provide referral data as part of the response of the authenticate method or when the SDK is initialized if a previous valid session was found. More info

Repost an activity

Create a new activity and store the original activity’s id

val activity: GetSocialActivity // activity to repost
val newActivity = ActivityContent()
newActivity.withText("Check this out")
newActivity.addProperty("activity_id", activity.id)

Communities.postActivity(newActivity, target, { activity ->
    Log.d("Communities", "Activity posted")
}, { error ->
    Log.d("Communities", "Failed to post activity, error: $error")
})
let activity: Activity  //  activity to repost
let newActivity = ActivityContent()
newActivity.text = 'Check this out'
newActivity.properties['activity_id'] = activity.id

Communities.postActivity(newActivity, target: target, success: { activity in
    print("Activity posted")
}, failure: { error in
    print("Failed to post activity, error: \(error)")
})
var activity = Activity;  //  activity to repost
var newActivity = ActivityContent();
newActivity.text = 'Check this out';
newActivity.properties['activity_id'] = activity.id;

Communities.postActivity(newActivity, target)
    .then((result) => print('Activity posted'))
    .catchError((error) => print('Failed to post activity, error: $error'));
let activity: Activity;  //  activity to repost
let newActivity = new ActivityContent();
newActivity.text = 'Check this out';
newActivity.properties.activity_id = activity.id;

Communities.postActivity(newActivity, target)
    .then(() => console.log('Activity posted'))
    .catch((error) => console.error('Failed to post activity, error: ', error));
let activity: Activity;  //  activity to repost
let newActivity = new GetSocialSDK.ActivityContent({
    text: 'Check this out',
    properties: {
        activity_id: activity.id
    }
});

GetSocialSDK.Communities.postActivity(newActivity, target)
    .then(() => console.log('Activity posted'))
    .catch((error) => console.error('Failed to post activity, error: ', error));

Check and load the original activity

val activity: GetSocialActivity // activity in a feed
val originalActivityId: String? = activity.properties.get("activity_id")
if (originalActivityId != null) {
    // fetch the original activity
    Communities.getActivity(originalActivityId, { originalActivity ->
        Log.d("Communities", "Original activity: $originalActivity")
    }, { error ->
        Log.d("Communities", "Failed to load original activity, error: $error")
    })
}
let activity: Activity  //  activity in a feed
if let originalActivityId = activity.properties['activity_id'] {
    // fetch the original activity
    Communities.activity(originalActivityId, success: { originalActivity in
        print("Original activity: \(originalActivity)")
    }, failure: { error in
        print("Failed to load original activity, error: \(error)")
    })
}
var activity = Activity;  //  activity to repost
var originalActivityId = activity.properties['activity_id'];

// fetch the original activity
Communities.getActivity(originalActivityId)
    .then((activity) => print('Original activity: $activity'))
    .catchError((error) => print('Failed to load original activity, error: $error'));
let activity: Activity; // activity in a feed
const originalActivityId = activity.properties.activity_id;

// fetch the original activity
Communities.getActivity(originalActivityId)
    .then((activity) => console.log('Original activity:', activity))
    .catch((error) => console.error('Failed to load original activity, error: ', error));
let activity: Activity; // activity in a feed
const originalActivityId = activity.properties.activity_id;

// fetch the original activity
GetSocialSDK.Communities.getActivity(originalActivityId)
    .then((activity) => console.log('Original activity: ', activity))
    .catch((error) => console.error('Failed to load original activity, error: ', error));

Give us your feedback! Was this article helpful?

😀 🙁