text stringlengths 1 372 |
|---|
<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.0, |
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. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.