TEXT   31
package pastebin dart
Guest on 17th March 2023 01:37:05 PM


  1. import 'package:pastebin/pastebin.dart';
  2.  
  3. void main() async {
  4.   final primaryApiDevKey = '<your_api_dev_key>';
  5.  
  6.   final fallbackApiDevKey = '<your_api_dev_key>';
  7.  
  8.   final apiUserKey = '<your_api_user_key>';
  9.  
  10.   final username = '<your_pastebin_username>';
  11.  
  12.   final password = '<your_pastebin_password>';
  13.  
  14.   // Using Official Pastebin API with a single API Dev Key
  15.   var pastebinClient = withSingleApiDevKey(
  16.     apiDevKey: primaryApiDevKey,
  17.   );
  18.  
  19.   // Using Official Pastebin API with multiple API Dev Key
  20.   pastebinClient = withMultipleApiDevKey(
  21.     apiDevKeys: [
  22.       primaryApiDevKey,
  23.       fallbackApiDevKey,
  24.     ],
  25.   );
  26.  
  27.   // Publish new paste
  28.   final pasteText = 'Hello World!';
  29.  
  30.   final pasteResult = await pastebinClient.paste(pasteText: pasteText);
  31.  
  32.   print(pasteResult);
  33.  
  34.   // Publish new paste with options
  35.   final pasteName = 'Hello World!';
  36.  
  37.   final pasteWithOptionsResult = await pastebinClient.paste(
  38.     pasteText: pasteText,
  39.     options: PasteOptions(
  40.       pasteName: pasteName,
  41.       pasteVisiblity: Visibility.public,
  42.       pasteFormat: Format.dart,
  43.       apiUserKey: apiUserKey,
  44.       pasteExpireDate: ExpireDate.oneDay,
  45.     ),
  46.   );
  47.  
  48.   print(pasteWithOptionsResult);
  49.  
  50.   // Generate Pastebin API user key
  51.   final apiUserKeyResult = await pastebinClient.apiUserKey(
  52.     username: username,
  53.     password: password,
  54.   );
  55.  
  56.   print(apiUserKeyResult);
  57.  
  58.   // Delete paste
  59.   final pasteKey = '<paste_key>';
  60.  
  61.   final deletePasteResult = await pastebinClient.delete(
  62.     pasteKey: pasteKey,
  63.     userKey: apiUserKey,
  64.   );
  65.  
  66.   print(deletePasteResult);
  67.  
  68.   // Retrieve user pastes
  69.   final limit = 100;
  70.  
  71.   final pastesResult = await pastebinClient.pastes(
  72.     limit: limit,
  73.     userKey: apiUserKey,
  74.   );
  75.  
  76.   print(pastesResult);
  77.  
  78.   // Retrieve raw paste of user
  79.   var pasteVisibility = Visibility.private;
  80.  
  81.   final rawPasteOfUserResult = await pastebinClient.rawPaste(
  82.     pasteKey: pasteKey,
  83.     visibility: pasteVisibility,
  84.     userKey: apiUserKey,
  85.   );
  86.  
  87.   print(rawPasteOfUserResult);
  88.  
  89.   // Retrieve raw paste
  90.   pasteVisibility = Visibility.public;
  91.  
  92.   final rawPasteResult = await pastebinClient.rawPaste(
  93.     pasteKey: pasteKey,
  94.     visibility: pasteVisibility,
  95.   );
  96.  
  97.   print(rawPasteResult);
  98.  
  99.   // Retrieve user info
  100.  
  101.   final userInfoResult = await pastebinClient.userInfo(
  102.     userKey: apiUserKey,
  103.   );
  104.  
  105.   print(userInfoResult);
  106. }

Raw Paste

Login or Register to edit or fork this paste. It's free.