GetPollResultsAsync
Gets the voting results for a specific Sensei poll.
Method Signature
public async Task<SenseiPollVoteResultsResponse?> GetPollResultsAsync(string pollId)
Parameters
Parameter | Type | Description |
---|---|---|
pollId | string | The ID of the poll to get results for (obtained from GetActivePollAsync ) |
Returns
Returns a SenseiPollVoteResultsResponse
object containing the vote results and breakdown, or null
if the request failed.
Usage Example
// After casting a vote, get the results
string pollId = "poll-id-from-active-poll";
var results = await playSafeManager.GetPollResultsAsync(pollId);
if (results != null && results.Ok)
{
Debug.Log($"Total votes: {results.Data.Votes}");
// Display breakdown of votes
foreach (var option in results.Data.Breakdown)
{
Debug.Log($"Option '{option.Key}': {option.Value} votes");
}
}
Complete Workflow Example
// Complete poll workflow
string personaId = "your-persona-id";
// 1. Get active poll
var poll = await playSafeManager.GetActivePollAsync(personaId);
if (poll != null && poll.Ok && poll.Data != null)
{
// 2. Cast a vote
var vote = await playSafeManager.CastVoteAsync(poll.Data.Id, "yes");
if (vote != null && vote.Ok)
{
// 3. Get results
var results = await playSafeManager.GetPollResultsAsync(poll.Data.Id);
if (results != null && results.Ok)
{
Debug.Log($"Poll results - Total: {results.Data.Votes}");
foreach (var option in results.Data.Breakdown)
{
float percentage = (float)option.Value / results.Data.Votes * 100f;
Debug.Log($"{option.Key}: {option.Value} votes ({percentage:F1}%)");
}
}
}
}
Response Type
SenseiPollVoteResultsResponse
public class SenseiPollVoteResultsResponse
{
public bool Ok { get; set; }
public SenseiPollVoteResultsData Data { get; set; }
public string Message { get; set; }
}
SenseiPollVoteResultsData
public class SenseiPollVoteResultsData
{
public int Votes { get; set; }
public Dictionary<string, int> Breakdown { get; set; }
}
Properties
Property | Type | Description |
---|---|---|
Ok | bool | Indicates whether the request was successful |
Data.Votes | int | Total number of votes cast for this poll |
Data.Breakdown | Dictionary<string, int> | Vote count for each option |
Message | string | Response message from the server |
Error Handling
The method returns null
if:
- Network request fails
- Poll ID doesn't exist
- Response parsing fails
Always check for null
and verify the Ok
property before accessing the data.
Notes
- Results are available even while the poll is still active
- The
Breakdown
dictionary contains vote counts for each poll option - Use the
Votes
property to calculate percentages - Results are updated in real-time as new votes are cast
- You can call this method multiple times to get updated results