Polls¶
Create Polls¶
Supported SDK version
Polls are available in version 7.5.0 and above.
Your users are a great asset when it comes to gleaning insights or getting valuable feedback from them. Polls are an easy and quick way for you to solicit their opinions on your products, content, or anything really!. You can also let them create their own interesting image or text-based polls that allow for more creativity than ever before!
A poll is composed of a question and two or more options. Question can include image or video in addition to text, similarly the poll options could be either text options or image options.
Dashboard¶
Create a poll¶
-
Login to GetSocial Dashboard.
-
Go to Communities section.
-
Select a topic in which you want to create a poll.
-
Press New poll button.
-
Enter the question, add poll options, set end date, etc. When finished, press Post.
Check votes¶
-
Select an activity or announcement with poll content.
-
Check votes.
SDK¶
Poll Content¶
Polls can be created by adding PollContent
to an activity:
var activityContent = ActivityContent()
var pollContent = PollContent()
// set end date (optional)
pollContent = pollContent.withEndDate(123) // users can vote until end date
// allow multiple votes
pollContent = pollContent.withAllowMultipleVotes(true)
// add poll options
pollContent.addPollOptions(pollOptions);
activityContent = activityContent.withPoll(pollContent)
// post the activity
Communities.postActivity(activity, target, { result: GetSocialActivity ->
print("Communities", "Posted activity with poll: $result")
}, { error: GetSocialError ->
print("Communities", "Failed to post activity with poll: $error")
})
var activityContent = ActivityContent()
var pollContent = PollContent()
// set end date (optional)
pollContent.endDate = // users can vote until end date
// allow multiple votes
pollContent.allowMultipleVotes = true
// add poll options
pollContent.options = [pollOptions]
activityContent.poll = pollContent
// post the activity
Communities.postActivity(activityContent, target: target, success: { activity in
print("Posted activity with poll: \(activity)")
}, failure: { error in
print("Failed to post activity with poll: \(error)")
})
var activityContent = new ActivityContent();
var pollContent = new PollContent();
// set end date (optional)
pollContent.EndDate = // users can vote until end date
// allow multiple votes
pollContent.AllowMultipleVotes = true;
// add poll options
pollContent.options = [pollOptions]
activityContent.Poll = pollContent
// post the activity
Communities.PostActivity(activityContent, Target, (activity) => {
Debug.Log("Posted activity with poll: " + activity);
}, (error) => {
Debug.Log("Failed to post activity with poll: " + error);
})
var activityContent = ActivityContent();
var pollContent = PollContent();
// set end date (optional)
pollContent.endDate = 123; // users can vote until end date
// allow multiple votes
pollContent.allowMultipleVotes = true;
// add poll options
pollContent.options = pollOptions;
activityContent.poll = pollContent;
// post the activity
Communities.postActivity(activity, target)
.then((result) => print('Posted activity with poll: $result'))
.catchError((error) => print('Failed to post activity with poll: $error'));
})
const activityContent = new ActivityContent();
const poll = new PollContent();
// set end date (optional)
poll.endDate = // users can vote until end date
// allow multiple votes
poll.allowMultipleVotes = true;
// add poll options
poll.options.push(pollOption);
activityContent.poll = poll;
// post the activity
Communities.postActivity(activityContent, target).then((activity) => {
console.log('Posted activity with poll: ' + activity);
}, (error) => {
console.log('Failed to post activity with poll: ' + error);
});
const poll = new GetSocialSDK.PollContent({
// set end date (optional)
// users can vote until end date
// endDate:
// allow multiple votes
allowMultipleVotes: true
});
// add poll options
poll.options.push(pollOption);
const activityContent = new GetSocialSDK.ActivityContent({
poll
});
// post the activity
GetSocialSDK.Communities.postActivity(activityContent, target)
.then((activity) => {
console.log('Posted activity with poll: ', activity);
}, (error) => {
console.log('Failed to post activity with poll: ', error);
});
Poll Option Content¶
var optionContent = PollOptionContent()
// set optionId, optional
optionContent = optionContent.withOptionId("option1")
// set option text
optionContent = optionContent.withText("Option A")
// or add an image or video
optionContent = optionContent.withAttachment(MediaAttachment.imageUrl("someurl"))
let optionContent = PollOptionContent()
// set optionId, optional
optionContent.optionId = "option1"
// set option text
optionContent.text = "Option A"
// or add an image or video
optionContent.attachment = MediaAttachment.imageUrl("someurl")
var optionContent = new PollOptionContent();
// set optionId, optional
optionContent.OptionId = "option1";
// set option text
optionContent.Text = "Option A";
// or add an image or video
optionContent.Attachment = MediaAttachment.WithImageUrl("someurl");
var optionContent = PollOptionContent();
// set optionId, optional
optionContent.optionId = 'option1';
// set option text
optionContent.text = 'Option A';
// or add an image or video
optionContent.attachment = MediaAttachment.withImageUrl('someurl');
let optionContent = new PollOptionContent();
// set optionId, optional
optionContent.optionId = 'option1';
// set option text
optionContent.text = 'Option A';
// or add an image or video
optionContent.attachment = MediaAttachment.withImageUrl('someurl');
let optionContent = new GetSocialSDK.PollOptionContent({
// set optionId, optional
optionId: 'option1',
// set option text
text: 'Option A',
// or add an image or video
attachment: GetSocialSDK.MediaAttachment.withImageUrl('someurl')
});
Mixing diffent contents
Mixing different contents is not supported, all options must either be text or image i.e. you cant have one option as text and another option as image for the same poll.
Filter Polls¶
Use the PollStatus
enum to filter activities with different poll statuses. By default all activities, with or without a poll, are returned.
var query = ActivitiesQuery.activitiesInTopic("cats")
query = query.withPollStatus(PollStatus.WITH_POLL) // only activities with a poll
// or
// query = query.withPollStatus(PollStatus.WITH_POLL_VOTED_BY_ME) // only activities with a poll, voted by current user
// query = query.withPollStatus(PollStatus.WITH_POLL_NOT_VOTED_BY_ME) // only activities with a poll, not voted by current user
Communities.getActivities(PagingQuery(query), { result: PagingResult<GetSocialActivity> ->
val activities = result.entries
print("Communities", "Activities: $activities")
}, { error: GetSocialError ->
print("Communities", "Failed to get activities: $error")
})
var query = ActivitiesQuery.inTopic("cats")
query = query.withPollStatus(.withPoll) // only activities with a poll
// or
// query = query.withPollStatus(.withPollVotedByMe) // only activities with a poll, voted by current user
// query = query.withPollStatus(.withPollNotVotedByMe) // only activities with a poll, not voted by current user
Communities.activities(ActivitiesPagingQuery(query), success: { result in
print("Activities: \(result.activities)")
}, failure: { error in
print("Failed to get activities: \(error)")
})
var query = ActivitiesQuery.InTopic("cats");
query = query.WithPollStatus(PollStatus.WithPoll); // only activities with a poll
// or
// query = query.WithPollStatus(PollStatus.WithPollVotedByMe); // only activities with a poll, voted by current user
// query = query.WithPollStatus(PollStatus.WithPollNotVotedByMe); // only activities with a poll, not voted by current user
Communities.GetActivities(new PagingQuery(query), (result) => {
Debug.Log("Activities: " + result.Entries");
}, (error) => {
Debug.Log("Failed to get activities: " + error);
})
var query = ActivitiesQuery.inTopic('cats');
query = query.withPollStatus(PollStatus.withPoll); // only activities with a poll
// or
// query = query.withPollStatus(PollStatus.votedByMe); // only activities with a poll, voted by current user
// query = query.withPollStatus(PollStatus.notedByMe); // only activities with a poll, not voted by current user
Communities.getActivities(PagingQuery(query!))
.then((value) => print('Activities: $result'));
.catchError((error) => print('Failed to get activities: $error');
let query = ActivitiesQuery.inTopic('cats');
query = query.withPollStatus(PollStatus.WithPoll);
// or
// query = query.withPollStatus(PollStatus.VotedByMe); // only activities with a poll, voted by current user
// query = query.withPollStatus(PollStatus.NotVotedByMe); // only activities with a poll, not voted by
Communities.getActivities(new PagingQuery(query)).then((result) => {
console.log('Activities: ', result.entries)');
}, (error) => {
console.log('Failed to get activities: ' + error);
});
let query = GetSocialSDK.ActivitiesQuery.inTopic('cats');
query = query.withPollStatus(GetSocialSDK.PollStatus.WithPoll);
// or
// only activities with a poll, voted by current user
// query = query.withPollStatus(GetSocialSDK.PollStatus.VotedByMe);
// only activities with a poll, not voted by current user
// query = query.withPollStatus(GetSocialSDK.PollStatus.NotVotedByMe);
GetSocialSDK.Communities.getActivities(new GetSocialSDK.PagingQuery(query))
.then((result) => {
console.log('Activities: ', result.entries);
}, (error) => {
console.log('Failed to get activities: ', error);
});
Vote on Polls¶
When a poll supports multiple votes, users can submit multiple votes at a time, if multiple votes are not supported, users can submit only one vote on a poll at a time.
Get Votes¶
Get Users who voted for a poll¶
val activityId = // id of activity with poll
val query = VotesQuery.forActivity(activityId)
Communities.getVotes(PagingQuery(query), { result: PagingResult<UserVotes> ->
print("Communities: " + result.entries)
}, { error: GetSocialError ->
print("Failed to get votes: \(error)")
})
let activityId = // id of activity with poll
let query = VotesQuery.forActivity(activityId)
Communities.votes(VotesPagingQuery(query), success: { result in
print("Votes: \(result.votes)")
}, failure: { error in
print("Failed to get votes: \(error)")
})
var activityId = // id of activity with poll
var query = VotesQuery.ForActivity(activityId);
Communities.GetVotes(new PagingQuery(query), (result) => {
Debug.Log("Votes: " + result.Entries);
}, (error) =>
Debug.Log("Failed to get votes: " + error);
})
var activityId = // id of activity with poll
var query = VotesQuery.forActivity(activityId);
Communities.getVotes(PagingQuery(query))
.then((result) => print('Votes: $result'));
.catchError((error) => print('Failed to get votes: $error'));
const activityId = // id of activity with poll
const query = VotesQuery.forActivity(activityId);
Communities.getVotes(new PagingQuery(query)).then((result) => {
console.log('Votes: ' + result.entries);
}, (error) => {
console.log('Failed to get votes: ' + error);
});
const activityId = // id of activity with poll
const query = GetSocialSDK.VotesQuery.forActivity(activityId);
GetSocialSDK.Communities.getVotes(new GetSocialSDK.PagingQuery(query))
.then((result) => {
console.log('Votes: ', result.entries);
}, (error) => {
console.log('Failed to get votes: ', error);
});
Get Number of Total Votes¶
val activity: GetSocialActivity = // activity with a poll
val totalVotes = activity.poll.totalVotesCount
let activity = // activity with a poll
let totalVotes = activity.poll?.totalVotes
var activity = // activity with a poll
var totalVotes = activity.Poll.TotalVotes;
var activity: GetSocialActivity = // activity with a poll
var totalVotes = activity.poll.totalVotesCount;
const activity = // activity with a poll
const totalVotes = activity.poll.totalVotes;
const activity = // activity with a poll
const totalVotes = activity.poll.totalVotes;
Get Number of Votes on a Poll Option¶
val activity: GetSocialActivity = // activity with a poll
val poll = activity.poll
val pollOptions = poll.pollOptions
pollOptions.forEach {
print("votes on ${it.optionId}: ${it.voteCount}")
}
let activity = // activity with poll
let poll = activity.poll
let pollOptions = poll.options
pollOptions.forEach {
print("votes on [\($0.optionId)]: \($0.voteCount)")
}
var activity = // activity with a poll
var poll = activity.Poll;
var pollOptions = poll.Options;
pollOptions.ForEach((option) => {
Debug.Log("votes on [" + option.OptionId + "]: " + option.VoteCount);
});
var activity: GetSocialActivity = // activity with a poll
var poll = activity.poll
var pollOptions = poll.pollOptions
pollOptions.forEach((pollOption) =>
print('votes on ${pollOption.optionId}: ${pollOption.voteCount}');
);
const activity = // activity with poll
const poll = activity.poll;
const pollOptions = poll.options;
pollOptions.forEach(option => {
console.log('votes on ' + option.optionId + ': ' + option.voteCount);
})
const activity = // activity with poll
const poll = activity.poll;
const pollOptions = poll.options;
pollOptions.forEach(option => {
console.log('votes on ' + option.optionId + ': ' + option.voteCount);
})
Add Votes¶
If multiple votes are allowed then users can vote on multiple options. Use add votes to keep existing votes and add votes for another options.
val activityId = // id of activity with a poll
val optionIds = HashSet(listOf("option1", "option2"))
Communities.addVotes(optionIds, activityId, {
print("Successfully added votes.")
}, { error: GetSocialError ->
print("Failed to add votes: $error")
})
let activityId = // id of activity with a poll
let optionIds: Set = ["option1", "option2"] // poll option ids to vote on
Communities.addVotes(optionIds), activityId: activityId, success: {
print("Successfully added votes.")
}, failure: { [weak self] error in
print("Failed to add votes: \(error)")
})
var activityId = // id of activity with a poll
var optionIds = new HashSet<string>{ "option1", "option2" }; // poll option ids to vote on
Communities.AddVotes(optionIds, activityId, () => {
Debug.Log("Successfully added votes.");
}, (error) => {
Debug.Log("Failed to add votes, error: " + error);
});
var activityId = // id of activity with a poll
var optionIds = Set.from(['option1', 'option2']);
Communities.addVotes(optionIds, activityId)
.then(() => print('Successfully added votes.'));
.catchError((error) => print('Failed to add votes: $error'));
const activityId = // id of activity with a poll
const optionIds = ['option1', 'option2'] // poll option ids to vote on
Communities.addVotes(optionIds, activityId).then((result) => {
console.log('Successfully added votes.');
}, (error) => {
console.log('Failed to add votes: ' + error);
});
const activityId = // id of activity with a poll
const optionIds = ['option1', 'option2'] // poll option ids to vote on
GetSocialSDK.Communities.addVotes(optionIds, activityId)
.then((result) => {
console.log('Successfully added votes.');
}, (error) => {
console.log('Failed to add votes: ', error);
});
Set Votes¶
Setting votes removes existing votes and keeps the provided ones.
val activityId = // id of activity with a poll
val optionIds = HashSet(listOf("option1", "option2"))
Communities.setVotes(optionIds, activityId, {
print("Successfully set votes.")
}, { error: GetSocialError ->
print("Failed to set votes: $error")
})
let activityId = // id of activity with a poll
let optionIds: Set = ["option1", "option2"] // poll option ids to vote on
Communities.setVotes(optionIds), activityId: activityId, success: {
print("Successfully set votes.")
}, failure: { [weak self] error in
print("Failed to set votes: \(error)")
})
var activityId = // id of activity with a poll
var optionIds = new HashSet<string>{ "option1", "option2" }; // poll option ids to vote on
Communities.SetVotes(optionIds, activityId, () => {
Debug.Log("Successfully set votes.");
}, (error) => {
Debug.Log("Failed to set votes, error: " + error);
});
var activityId = // id of activity with a poll
var optionIds = Set.from(['option1', 'option2']);
Communities.setVotes(optionIds, activityId)
.then(() => print('Successfully set votes.'));
.catchError((error) => print('Failed to set votes: $error'));
const activityId = // id of activity with a poll
const optionIds = ['option1', 'option2'] // poll option ids to vote on
Communities.setVotes(optionIds, activityId).then((result) => {
console.log('Successfully set votes.');
}, (error) => {
console.log('Failed to set votes: ' + error);
});
const activityId = // id of activity with a poll
const optionIds = ['option1', 'option2'] // poll option ids to vote on
GetSocialSDK.Communities.setVotes(optionIds, activityId)
.then((result) => {
console.log('Successfully set votes.');
}, (error) => {
console.log('Failed to set votes: ', error);
});
Remove Votes¶
val activityId = // id of activity with a poll
val optionIds = HashSet(listOf("option1", "option2"))
Communities.removeVotes(optionIds, activityId, {
print("Successfully removed votes.")
}, { error: GetSocialError ->
print("Failed to remove votes: $error")
})
let activityId = // id of activity with a poll
let optionIds: Set = ["option1", "option2"] // poll option ids to remove
Communities.removeVotes(optionIds), activityId: activityId, success: {
print("Successfully removed votes.")
}, failure: { [weak self] error in
print("Failed to remove votes: \(error)")
})
var activityId = // id of activity with a poll
var optionIds = new HashSet<string>{ "option1", "option2" }; // poll option ids to remove
Communities.RemoveVotes(optionIds, activityId, () => {
Debug.Log("Successfully removed votes.");
}, (error) => {
Debug.Log("Failed to remove votes, error: " + error);
});
var activityId = // id of activity with a poll
var optionIds = Set.from(['option1', 'option2']);
Communities.removeVotes(optionIds, activityId)
.then(() => print('Successfully removed votes.'));
.catchError((error) => print('Failed to remove votes: $error'));
const activityId = // id of activity with a poll
const optionIds = ['option1', 'option2'] // poll option ids to remove
Communities.removeVotes(optionIds, activityId).then((result) => {
console.log('Successfully removed votes.');
}, (error) => {
console.log('Failed to remove votes: ' + error);
});
const activityId = // id of activity with a poll
const optionIds = ['option1', 'option2'] // poll option ids to remove
GetSocialSDK.Communities.removeVotes(optionIds, activityId)
.then((result) => {
console.log('Successfully removed votes.');
}, (error) => {
console.log('Failed to remove votes: ', error);
});