mirror of
https://github.com/tommyxchow/frosty.git
synced 2025-08-06 17:48:14 +08:00
Add request file
This commit is contained in:
37
lib/utility/request.dart
Normal file
37
lib/utility/request.dart
Normal file
@ -0,0 +1,37 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class Request {
|
||||
static Future<String> getDefaultToken() async {
|
||||
final url = Uri(
|
||||
scheme: 'https',
|
||||
host: 'id.twitch.tv',
|
||||
path: '/oauth2/token',
|
||||
queryParameters: {
|
||||
'client_id': const String.fromEnvironment('CLIENT_ID'),
|
||||
'client_secret': const String.fromEnvironment('SECRET'),
|
||||
'grant_type': 'client_credentials'
|
||||
},
|
||||
);
|
||||
|
||||
final response = await http.post(url);
|
||||
final decoded = jsonDecode(response.body);
|
||||
print(decoded);
|
||||
return decoded['access_token'];
|
||||
}
|
||||
|
||||
static void getTopChannels({required String token}) async {
|
||||
final url = Uri.parse('https://api.twitch.tv/helix/streams?first=10');
|
||||
final headers = {'Authorization': 'Bearer $token', 'Client-Id': const String.fromEnvironment('CLIENT_ID')};
|
||||
final response = await http.get(url, headers: headers);
|
||||
final decoded = jsonDecode(response.body);
|
||||
print(decoded);
|
||||
final data = decoded['data'];
|
||||
print(data);
|
||||
|
||||
//final List<EmoteBTTVGlobal> emotes = decoded.map((emote) => EmoteBTTVGlobal.fromJson(emote)).toList();
|
||||
}
|
||||
}
|
||||
|
||||
enum HTTPMethod { GET, POST }
|
Reference in New Issue
Block a user