predictions - YoYoGames/GMEXT-Twitch GitHub Wiki

Predictions

Functions

These are the functions of this module:



Back To Top

twitch_predictions_get_predictions

Twitch Endpoint: Get Predictions

This function gets a list of Channel Points Predictions that the broadcaster created.

Note

Requires a user access token that includes the TWITCH_SCOPE_CHANNEL_READ_PREDICTIONS or TWITCH_SCOPE_CHANNEL_MANAGE_PREDICTIONS scope.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Success Callback, or Failure Callback.


Syntax:

twitch_predictions_get_predictions(broadcaster_id, optionals, callback_success, callback_failed)
Argument Type Description
broadcaster_id String The ID of the broadcaster whose predictions you want to get. This ID must match the user ID in the user access token.
optionals Struct The optional parameters to be passed into the function:

- id : Real or Array of Real : The ID of the prediction to get. To specify more than one ID, pass an array with the ID of each prediction you want to get. You may specify a maximum of 25 IDs. The endpoint ignores duplicate IDs and those not owned by the broadcaster.
- first : String : The maximum number of items to return per page in the response. The minimum page size is 1 item per page and the maximum is 25 items per page. The default is 20.
- after : String : The cursor used to get the next page of results. The Pagination struct in the response contains the cursor's value. Read more
callback_success Function Triggered if the request succeeded
callback_failed Function Triggered if the request failed



Returns:

N/A


Triggers:

Success Callback

These members are returned in the success callback:

Member Type Description
data Array The broadcaster's list of Channel Points Predictions. The list is sorted in descending ordered by when the prediction began (the most recent prediction is first). The list is empty if the broadcaster hasn't created predictions.
 ├── id String An ID that identifies this prediction.
 ├── broadcaster_id String An ID that identifies the broadcaster that created the prediction.
 ├── broadcaster_name String The broadcaster's display name.
 ├── broadcaster_login String The broadcaster's login name.
 ├── title String The question that the prediction asks. For example, Will I finish this entire pizza?
 ├── winning_outcome_id String The ID of the winning outcome. Is undefined unless status is "RESOLVED".
 ├── outcomes Array The list of possible outcomes for the prediction.
         ├── id String An ID that identifies this outcome.
         ├── title String The outcome's text.
         ├── users Real The number of unique viewers that chose this outcome.
         ├── channel_points Real The number of Channel Points spent by viewers on this outcome.
         ├── top_predictors Array A list of viewers who were the top predictors; otherwise, undefined if none.
                 ├── user_id String An ID that identifies the viewer.
                 ├── user_name String The viewer's display name.
                 ├── user_login String The viewer's login name.
                 ├── channel_points_used Real The number of Channel Points the viewer spent.
                 └── channel_points_won Real The number of Channel Points distributed to the viewer.
         └── color String The color that visually identifies this outcome in the UX. Possible values are: "BLUE", "PINK". If the number of outcomes is two, the color is "BLUE" for the first outcome and "PINK" for the second outcome. If there are more than two outcomes, the color is "BLUE" for all outcomes.
 ├── prediction_window Real The length of time (in seconds) that the prediction will run for.
 ├── status String The prediction's status. Valid values are: "ACTIVE" - The Prediction is running and viewers can make predictions. "CANCELED" - The broadcaster canceled the Prediction and refunded the Channel Points to the participants. "LOCKED" - The broadcaster locked the Prediction, which means viewers can no longer make predictions. "RESOLVED" - The winning outcome was determined and the Channel Points were distributed to the viewers who predicted the correct outcome.
 ├── created_at String The UTC date and time of when the Prediction began.
 ├── ended_at String The UTC date and time of when the Prediction ended. If status is "ACTIVE", this is set to undefined.
 └── locked_at String The UTC date and time of when the Prediction was locked. If status is not "LOCKED", this is set to undefined.
pagination Struct Contains the information used to page through the list of results. The struct is empty if there are no more pages left to page through. Read More
 └── cursor String The cursor used to get the next page of results. Use the cursor to set the request's after parameter.

Failure Callback

This method is triggered on failure.




Back To Top

twitch_predictions_create_prediction

Twitch Endpoint: Create Prediction

This function creates a Channel Points Prediction.

With a Channel Points Prediction, the broadcaster poses a question and viewers try to predict the outcome. The prediction runs as soon as it's created. The broadcaster may run only one prediction at a time.

Note

Requires a user access token that includes the TWITCH_SCOPE: TWITCH_SCOPE_CHANNEL_MANAGE_PREDICTIONS.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Success Callback, or Failure Callback.


Syntax:

twitch_predictions_create_prediction(broadcaster_id, title, outcomes, prediction_window, callback_success, callback_failed)
Argument Type Description
broadcaster_id String The ID of the broadcaster that's running the prediction. This ID must match the user ID in the user access token.
title String The question that the broadcaster is asking. For example, Will I finish this entire pizza? The title is limited to a maximum of 45 characters.
outcomes Array The list of possible outcomes that the viewers may choose from. The list must contain a minimum of 2 choices and up to a maximum of 10 choices.
prediction_window Real The length of time (in seconds) that the prediction will run for. The minimum is 30 seconds and the maximum is 1800 seconds (30 minutes).
callback_success Function Triggered if the request succeeded
callback_failed Function Triggered if the request failed



Returns:

N/A


Triggers:

Success Callback

These members are returned in the success callback:

Member Type Description
data Array A list that contains the single prediction that you created.
 ├── id String An ID that identifies this prediction.
 ├── broadcaster_id String An ID that identifies the broadcaster that created the prediction.
 ├── broadcaster_name String The broadcaster's display name.
 ├── broadcaster_login String The broadcaster's login name.
 ├── title String The question that the prediction asks. For example, Will I finish this entire pizza?
 ├── winning_outcome_id String The ID of the winning outcome. Is undefined unless status is "RESOLVED".
 ├── outcomes Array The list of possible outcomes for the prediction.
         ├── id String An ID that identifies this outcome.
         ├── title String The outcome's text.
         ├── users Real The number of unique viewers that chose this outcome.
         ├── channel_points Real The number of Channel Points spent by viewers on this outcome.
         ├── top_predictors Array A list of viewers who were the top predictors; otherwise, undefined if none.
                 ├── user_id String An ID that identifies the viewer.
                 ├── user_name String The viewer's display name.
                 ├── user_login String The viewer's login name.
                 ├── channel_points_used Real The number of Channel Points the viewer spent.
                 └── channel_points_won Real The number of Channel Points distributed to the viewer.
         └── color String The color that visually identifies this outcome in the UX. Possible values are: "BLUE", "PINK". If the number of outcomes is two, the color is "BLUE" for the first outcome and "PINK" for the second outcome. If there are more than two outcomes, the color is "BLUE" for all outcomes.
 ├── prediction_window Real The length of time (in seconds) that the prediction will run for.
 ├── status String The prediction's status. Valid values are: "ACTIVE" - The Prediction is running and viewers can make predictions. "CANCELED" - The broadcaster canceled the Prediction and refunded the Channel Points to the participants. "LOCKED" - The broadcaster locked the Prediction, which means viewers can no longer make predictions. "RESOLVED" - The winning outcome was determined and the Channel Points were distributed to the viewers who predicted the correct outcome.
 ├── created_at String The UTC date and time of when the Prediction began.
 ├── ended_at String The UTC date and time of when the Prediction ended. If status is "ACTIVE", this is set to undefined.
 └── locked_at String The UTC date and time of when the Prediction was locked. If status is not "LOCKED", this is set to undefined.

Failure Callback

This method is triggered on failure.




Back To Top

twitch_predictions_end_prediction

Twitch Endpoint: End Prediction

This function locks, resolves, or cancels a Channel Points Prediction.

Note

Requires a user access token that includes the TWITCH_SCOPE: TWITCH_SCOPE_CHANNEL_MANAGE_PREDICTIONS.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Success Callback, or Failure Callback.


Syntax:

twitch_predictions_end_prediction(broadcaster_id, id, status, optionals, callback_success, callback_failed)
Argument Type Description
broadcaster_id String The ID of the broadcaster that's running the prediction. This ID must match the user ID in the user access token.
id String The ID of the prediction to update.
status String The status to set the prediction to. Possible case-sensitive values are: "RESOLVED" - The winning outcome is determined and the Channel Points are distributed to the viewers who predicted the correct outcome. "CANCELED" - The broadcaster is canceling the prediction and sending refunds to the participants. "LOCKED" - The broadcaster is locking the prediction, which means viewers may no longer make predictions. The broadcaster can update an active prediction to "LOCKED", "RESOLVED", or "CANCELED"; and update a locked prediction to "RESOLVED" or "CANCELED".The broadcaster has up to 24 hours after the prediction window closes to resolve the prediction. If not, Twitch sets the status to "CANCELED" and returns the points.
optionals Struct The optional parameters to be passed into the function:

- winning_outcome_id : String : The ID of the winning outcome. You must set this parameter if you set status to "RESOLVED".
callback_success Function Triggered if the request succeeded
callback_failed Function Triggered if the request failed



Returns:

N/A


Triggers:

Success Callback

These members are returned in the success callback:

Member Type Description
data Array A list that contains the single prediction that you updated.
 ├── id String An ID that identifies this prediction.
 ├── broadcaster_id String An ID that identifies the broadcaster that created the prediction.
 ├── broadcaster_name String The broadcaster's display name.
 ├── broadcaster_login String The broadcaster's login name.
 ├── title String The question that the prediction asks. For example, Will I finish this entire pizza?
 ├── winning_outcome_id String The ID of the winning outcome. Is undefined unless status is "RESOLVED".
 ├── outcomes Array The list of possible outcomes for the prediction.
         ├── id String An ID that identifies this outcome.
         ├── title String The outcome's text.
         ├── users Real The number of unique viewers that chose this outcome.
         ├── channel_points Real The number of Channel Points spent by viewers on this outcome.
         ├── top_predictors Array A list of viewers who were the top predictors; otherwise, undefined if none.
                 ├── user_id String An ID that identifies the viewer.
                 ├── user_name String The viewer's display name.
                 ├── user_login String The viewer's login name.
                 ├── channel_points_used Real The number of Channel Points the viewer spent.
                 └── channel_points_won Real The number of Channel Points distributed to the viewer.
         └── color String The color that visually identifies this outcome in the UX. Possible values are: "BLUE", "PINK". If the number of outcomes is two, the color is "BLUE" for the first outcome and "PINK" for the second outcome. If there are more than two outcomes, the color is "BLUE" for all outcomes.
 ├── prediction_window Real The length of time (in seconds) that the prediction will run for.
 ├── status String The prediction's status. Valid values are: "ACTIVE" - The Prediction is running and viewers can make predictions. "CANCELED" - The broadcaster canceled the Prediction and refunded the Channel Points to the participants. "LOCKED" - The broadcaster locked the Prediction, which means viewers can no longer make predictions. "RESOLVED" - The winning outcome was determined and the Channel Points were distributed to the viewers who predicted the correct outcome.
 ├── created_at String The UTC date and time of when the Prediction began.
 ├── ended_at String The UTC date and time of when the Prediction ended. If status is "ACTIVE", this is set to undefined.
 └── locked_at String The UTC date and time of when the Prediction was locked. If status is not "LOCKED", this is set to undefined.

Failure Callback

This method is triggered on failure.



⚠️ **GitHub.com Fallback** ⚠️