createScriptInstance static method

Future<Reddit> createScriptInstance({
  1. String? clientId,
  2. String? clientSecret,
  3. String? userAgent,
  4. String? username,
  5. String? password,
  6. Uri? tokenEndpoint,
  7. Uri? authEndpoint,
  8. Uri? configUri,
  9. String siteName = 'default',
})

Creates a new authenticated Reddit instance for use with personal use scripts.

clientId is the identifier associated with your authorized application on Reddit. To get a client ID, create an authorized application here.

clientSecret is the unique secret associated with your client ID. This is required for script and web applications.

userAgent is an arbitrary identifier used by the Reddit API to differentiate between client instances. This should be relatively unique.

username and password is a valid Reddit username password combination. These fields are required in order to perform any account actions or make posts.

tokenEndpoint is a Uri to an alternative token endpoint. If not provided, defaultTokenEndpoint is used.

authEndpoint is a Uri to an alternative authentication endpoint. If not provided, defaultAuthTokenEndpoint is used.

configUri is a Uri pointing to a 'draw.ini' file, which can be used to populate the previously described parameters.

siteName is the name of the configuration to use from draw.ini. Defaults to 'default'.

Implementation

static Future<Reddit> createScriptInstance(
    {String? clientId,
    String? clientSecret,
    String? userAgent,
    String? username,
    String? password,
    Uri? tokenEndpoint,
    Uri? authEndpoint,
    Uri? configUri,
    String siteName = 'default'}) async {
  final reddit = Reddit._scriptInstance(clientId, clientSecret, userAgent,
      username, password, tokenEndpoint, authEndpoint, configUri, siteName);
  final initialized = await reddit._initializedCompleter.future;
  if (initialized) {
    return reddit;
  }
  throw DRAWAuthenticationError('Unable to authenticate with Reddit');
}