Requests from this Android client application <empty> are blocked - Google APIs error Flutter

413

A answered here, we need to pass package name and SHA1 key name in headers. So my new request would look like this:

const SHA1 = "0000000000000000000000000000000000000000";
const PACKAGE_NAME = "com.yourapp.name";
const HEADERS = {
      'Content-Type': 'application/json',
      'X-Android-Package': PACKAGE_NAME,
      'X-Android-Cert': SHA1b,
    };
const FETCH_LINK =
        "$BASE_URL?part=$PART&playlistId=$PLAYLIST_ID&key=$API_KEY&maxResults=$MAX_RESULTS";
var response = await http.get(Uri.parse(FETCH_LINK));
Share:
413
Apoorv pandey
Author by

Apoorv pandey

Updated on January 02, 2023

Comments

  • Apoorv pandey
    Apoorv pandey over 1 year

    Problem description: I am using Youtube Data API to fetch some videos using the API key in a Flutter app. I have used this code to fetch my data:

        const FETCH_LINK =
            "$BASE_URL?part=$PART&playlistId=$PLAYLIST_ID&key=$API_KEY&maxResults=$MAX_RESULTS";
        var response = await http.get(Uri.parse(FETCH_LINK));
    

    When I set the Applications restrictions to "None" in Credentials tab in GCP console of the project I'm getting my Data perfectly

    Now when I try to restrict the data to only Android apps Its showing this error:

    {error: {code: 403, message: Requests from this Android client application <empty> are blocked., errors: [{message: Requests from this Android client application <empty> are blocked., domain: global, reason: forbidden}], status: PERMISSION_DENIED, details: [{@type: type.googleapis.com/google.rpc.ErrorInfo, reason: API_KEY_ANDROID_APP_BLOCKED, domain: googleapis.com, metadata: {service: youtube.googleapis.com, consumer:
    

    What I have already checked: I have added Debug and Release certificates and android package name correctly in the credentials tab.

    What could be the possible error here? Is there anything I need to pass as headers in my request?

    This is the endpoint I'm trying to fetch

    https://youtube.googleapis.com/youtube/v3/playlistItems
    

    My settings look like this: enter image description here

    • Muhammad Ashir
      Muhammad Ashir over 2 years
      Can you share the Endpoint URL so I can try it my end.?
    • Apoorv pandey
      Apoorv pandey over 2 years
      Added in Question, please check @MuhammadAshir
  • Muhammad Ashir
    Muhammad Ashir over 2 years
    You may can restrict to Android by adding your package name along with SHA-1 Key or can go with a key that is not restricted to a specific platform.
  • Apoorv pandey
    Apoorv pandey over 2 years
    No but I have set the API restriction to youtube data API, Selected APIs: YouTube Data API v3
  • Muhammad Ashir
    Muhammad Ashir over 2 years
    Can you let me know about Application restrictions?
  • Apoorv pandey
    Apoorv pandey over 2 years
    I have added my ss in question please check, also is it working for your device when you set the API restrictions to Youtube data API?
  • Muhammad Ashir
    Muhammad Ashir over 2 years
    yes, But you need to add your app properly with SHA-1 key Please generate it through methods given by Google Developer Console while restricting the key because that can cause the issue also otherwise try by setting it to none then it should work.
  • Apoorv pandey
    Apoorv pandey over 2 years
    Yes, I got the keys from the commands given in right of the image I have uploaded in the question which are correct as I verified them on my device using third party apps too!
  • Apoorv pandey
    Apoorv pandey over 2 years