Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

YouTube Data API Error: Requests from this Android client application com.pakage are blocked

$
0
0

I am trying to subscribe a YouTube channel in flutter app for both in Android and IOS.I am using the Google Sign in to get users' authorisation to access YouTube Data. I am using the following access level:

'https://www.googleapis.com/auth/youtube.force-ssl'

In the following method, I am trying to subscribe a channel on user's behalf when user clicks on Subscribe button. I got the Authentication or access token from Google Sign in and pass 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 = {'part': 'snippet','kind': 'youtube#channel','channelId': channelId,'key': API_KEY,    };    Uri uri = Uri.https(_baseUrl, '/youtube/v3/subscriptions', parameters);    Map<String, String> headers = {'Authorization': authToken,      HttpHeaders.acceptHeader: 'application/json',      HttpHeaders.contentTypeHeader: 'application/json','X-Android-Package': package_name.toLowerCase(),'X-Android-Cert': SHA_1.toLowerCase(),    };    var response = await http.post(uri, headers: headers);    if (response.statusCode == 200) {      var data = json.decode(response.body);      return true;    } else {      // throw json.decode(response.body)['error']['message'];      print("SUBSCRIBEERROR: " + json.decode(response.body)['error']['message']);      return false;    }  }

In the Google API Console, I have created API keys for both android and IOS. There are two OAuth 2.0 Client IDs that are auto created by google service.

Could you please guide what is the problem and what I am missing here?

Thank you


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>