[ad_1]
I’m making an attempt to subscribe a YouTube channel in flutter app for each in Android and IOS.
I’m utilizing the Google Register to get customers’ authorisation to entry YouTube Knowledge. I’m utilizing the next entry degree:
‘https://www.googleapis.com/auth/youtube.force-ssl’
Within the following methodology, I’m making an attempt to subscribe a channel on person’s behalf when person clicks on Subscribe button. I bought the Authentication or entry token from Google Register and go it with my POST request.
Future<bool> subscribeYoutubeChannel({required String channelId}) async {
Map<String, String> map =
await MainScreenVideoSmartApp.currentUser?.authHeaders ?? null!;
String? authToken = map['Authorization'];
if (authToken == null)
return false;
String API_KEY = "";
if(Platform.isIOS){
API_KEY = API_KEY_IOS;
} else if (Platform.isAndroid){
API_KEY = API_KEY_ANDROID;
}
Map<String, String> parameters = {
'half': 'snippet',
'variety': 'youtube#channel',
'channelId': channelId,
'key': API_KEY,
};
Uri uri = Uri.https(_baseUrl, '/youtube/v3/subscriptions', parameters);
Map<String, String> headers = {
'Authorization': authToken,
HttpHeaders.acceptHeader: 'utility/json',
HttpHeaders.contentTypeHeader: 'utility/json',
'X-Android-Package deal': package_name.toLowerCase(),
'X-Android-Cert': SHA_1.toLowerCase(),
};
var response = await http.submit(uri, headers: headers);
if (response.statusCode == 200) {
var knowledge = json.decode(response.physique);
return true;
} else {
// throw json.decode(response.physique)['error']['message'];
print("SUBSCRIBEERROR: " + json.decode(response.physique)['error']['message']);
return false;
}
}
Within the Google API Console, I’ve created API keys for each android and IOS. There are two OAuth 2.0 Shopper IDs which are auto created by google service.
Might you please information what’s the drawback and what I’m lacking right here?
Thanks
[ad_2]
