google_photos 1.0.3

DEPRECATED #

Google has added Google Photos to the GoogleAPIs dart package now. I will no longer update this plugin.

Google Photos Autogenerated API client #

Google Photos does not yet have a first-party Dart SDK, so this is an unofficial API client autogenerated from Google Photo's API discovery doc

Caveat lector: Although this library is completely autogenerated using discoveryapis_generator, it is also not tested. I'm using it in my own projects and have not run into any problems, but please open an issue if you run into any problems.

Getting Started #

This API client is designed to be used with Dart's standard HTTP library. However, most of the endpoints require authentication headers to function properly.

Flutter #

You can use the google_sign_in package to get these headers, and extend the HTTP BaseClient to inject the auth headers on behalf of the API client. See the example directory.

In future, perhaps the Dart or Flutter teams will provide better integration of HTTP clients with the google_sign_in package.

Everything else #

Use the existing googleapis_auth library to get an authenticated HTTP client.

[1.0.2] - Moved example to fit analysis requirements, and updated homepage to point to github repo

[1.0.1] - Small update to pubspec to improve score and organization.

[1.0.0] - Google Photos v1 API

  • Initial release of autogenerated Google Photos API client. Generated from the v1 discovery doc

example/main.dart

import 'package:google_photos/google_photos.dart';
import 'package:http/http.dart';
import 'package:google_sign_in/google_sign_in.dart';

main() async {
  final GoogleSignIn googleSignIn = GoogleSignIn(scopes: <String>[
    'profile',
    'https://www.googleapis.com/auth/photoslibrary',
    'https://www.googleapis.com/auth/photoslibrary.sharing'
  ]);
  final user = await googleSignIn.signInSilently();
  final client = AuthenticatedClient(
    Client(),
    () => user.authHeaders,
    user.clearAuthCache,
  );
  final api = PhotoslibraryApi(client);
  // ... use API
}

class AuthenticatedClient extends BaseClient {
  final Client baseClient;
  final Future<Map<String, String>> Function() getAuthHeaders;
  final Future<void> Function() invalidHeadersCallback;

  AuthenticatedClient(
    this.baseClient,
    this.getAuthHeaders,
    this.invalidHeadersCallback,
  );

  Future<StreamedResponse> send(final BaseRequest request) async {
    var authHeaders = await getAuthHeaders();
    request.headers.addAll(authHeaders);
    var response = await baseClient.send(request);
    if (response.statusCode == 401) {
      // Headers are expired, or perhaps user has been logged out.
      // GoogleSignIn expects clients to inform it of invalid cached headers.
      await invalidHeadersCallback();
    }
    return response;
  }

  @override
  void close() {
    super.close();
    baseClient.close();
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  google_photos: ^1.0.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:google_photos/google_photos.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
41
Health:
Code health derived from static analysis. [more]
69
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
61
Learn more about scoring.

We analyzed this package on Aug 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:google_photos/google_photos.dart.

Health suggestions

Fix lib/api_client/photoslibrary.dart. (-31.34 points)

Analysis of lib/api_client/photoslibrary.dart reported 75 hints, including:

line 49 col 27: Use = to separate a named parameter from its default value.

line 50 col 30: Use = to separate a named parameter from its default value.

line 82 col 9: Don't explicitly initialize variables to null.

line 84 col 9: Don't explicitly initialize variables to null.

line 85 col 9: Don't explicitly initialize variables to null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
_discoveryapis_commons >=0.1.0 <0.2.0 0.1.8+1
http >=0.11.1 <0.13.0 0.12.0+2
Transitive dependencies
async 2.3.0
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
meta 1.1.7
path 1.6.4
pedantic 1.8.0+1
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
discoveryapis_generator ^0.9.11