google / googleapis.dart

Repository for building the googleapis packages
https://pub.dev/packages/googleapis
BSD 3-Clause "New" or "Revised" License
393 stars 119 forks source link

[YouTube Data API v3]: thumbnail url not working (`i.ytimg.com`) #643

Open Ahmadre opened 2 months ago

Ahmadre commented 2 months ago

At first thank you so much Google Team for this great pub package for requesting Google APIs in my Flutter App ❤️

Issue

I recognized that I could load Youtube thumbnails for each Video via my Debug-App and Debug Web-App without any problems.

But after creating a Release version (and yes I've setup --web-renderer html) all thumbnails lead to a CORS-Issue I couldn't resolve at all and also in my hosted Firebase Website it also leads to the same error.

Possible solution

After investigating and looking after how others solve this, I found this:

https://github.com/sarbagyastha/youtube_player_flutter/blob/7b4e615d6f8102d83ce11517f0746cc236d930d8/packages/youtube_player_iframe/lib/src/controller/youtube_player_controller.dart#L417

Instead of i.ytimg.com they're generating the url with i3.ytimg.com.

After testing this in my own Firebase Project it solved all of my CORS-Issues directly by replacing all of my urls i'm getting by the current youtube client api.

Workaround

Image.network(
  thumbnails!.standard!.url!.replaceAll('i.ytimg.com', 'i3.ytimg.com'),
  errorBuilder: (context, error, stackTrace) {
    return const Column(
      children: [
        Icon(Icons.error),
        Text('Error loading thumbnail'),
      ],
    );
  },
  gaplessPlayback: true,
),