text
stringlengths
1
474
<topic_end>
<topic_start>Google APIs
The Google APIs package exposes dozens of Google
services that you can use from Dart projects.This page describes how to use APIs that interact with
end-user data by using Google authentication.Examples of user-data APIs include
Calendar, Gmail, YouTube, and Firebase.info
The only APIs you should use directly from your Flutter
project are those that access user data using Google authentication.APIs that require service accounts should not
be used directly from a Flutter application.
Doing so requires shipping service credentials as part
of your application, which is not secure.
To use these APIs,
we recommend creating an intermediate service.To add authentication to Firebase explicitly, check out the
Add a user authentication flow to a Flutter app using FirebaseUI
codelab and the
Get Started with Firebase Authentication on Flutter docs.<topic_end>
<topic_start>
Overview
To use Google APIs, follow these steps:<topic_end>
<topic_start>
1. Pick the desired API
The documentation for package:googleapis lists
each API as a separate Dart library&emdash;in a
name_version format.
Check out youtube_v3 as an example.Each library might provide many types,
but there is one root class that ends in Api.
For YouTube, it’s YouTubeApi.Not only is the Api class the one you need to
instantiate (see step 3), but it also
exposes the scopes that represent the permissions
needed to use the API. For example,
the Constants section of the
YouTubeApi class lists the available scopes.
To request access to read (but not write) an end-users
YouTube data, authenticate the user with
youtubeReadonlyScope.
<code_start>/// Provides the `YouTubeApi` class.
import 'package:googleapis/youtube/v3.dart';<code_end>
<topic_end>
<topic_start>
2. Enable the API
To use Google APIs you must have a Google account
and a Google project. You also
need to enable your desired API.This example enables YouTube Data API v3.
For details, see the getting started instructions.<topic_end>
<topic_start>
3. Authenticate the user with the required scopes
Use the google_sign_in package to
authenticate users with their Google identity.
Configure signin for each platform you want to support.
<code_start>/// Provides the `GoogleSignIn` class
import 'package:google_sign_in/google_sign_in.dart';<code_end>
When instantiating the GoogleSignIn class,
provide the desired scopes as discussed
in the previous section.
<code_start>final _googleSignIn = GoogleSignIn(
scopes: <String>[YouTubeApi.youtubeReadonlyScope],
);<code_end>
Follow the instructions provided by
package:google_sign_in
to allow a user to authenticate.Once authenticated,
you must obtain an authenticated HTTP client.<topic_end>
<topic_start>
4. Obtain an authenticated HTTP client
The extension_google_sign_in_as_googleapis_auth
package provides an extension method on GoogleSignIn
called authenticatedClient.
<code_start>import 'package:extension_google_sign_in_as_googleapis_auth/extension_google_sign_in_as_googleapis_auth.dart';<code_end>
Add a listener to onCurrentUserChanged
and when the event value isn’t null,
you can create an authenticated client.
<code_start>var httpClient = (await _googleSignIn.authenticatedClient())!;<code_end>
This Client instance includes the necessary
credentials when invoking Google API classes.<topic_end>
<topic_start>
5. Create and use the desired API class
Use the API to create the desired API type and call methods.
For instance:
<code_start>var youTubeApi = YouTubeApi(httpClient);
var favorites = await youTubeApi.playlistItems.list(
['snippet'],
playlistId: 'LL', // Liked List
);<code_end>
<topic_end>
<topic_start>
More information
You might want to check out the following:
<topic_end>
<topic_start>Supported deployment platforms
As of Flutter 3.19.3,
Flutter supports deploying apps the following combinations of
hardware architectures and operating system versions.
These combinations are called platforms.Flutter supports platforms in three tiers:Based on these tiers, Flutter supports deploying to the following platforms.Android supports IA32 (x86) in software emulation only.
<topic_end>
<topic_start>Desktop support for Flutter
Flutter provides support for compiling
a native Windows, macOS, or Linux desktop app.
Flutter’s desktop support also extends to plugins—you
can install existing plugins that support the Windows,
macOS, or Linux platforms, or you can create your own.info Note
This page covers developing apps for all desktop