Amazon Developer

as

Settings
Sign out
Notifications
Alexa
Amazonアプリストア
Ring
AWS
ドキュメント
Support
Contact Us
My Cases
開発
テスト
公開
収益化
ユーザーエンゲージメント
デバイスの仕様
リソース

Google APIとの統合

Google APIとの統合

A3L Authentication SDKは、Google APIとの統合をサポートしています。この統合を有効にすると、ユーザーがGoogleアカウントでアプリにログインした後、Googleサービスにアクセスできるようになります。現在、A3L AuthenticationはGoogleドライブのスコープをサポートしています。Googleドライブのスコープの詳細については、Google開発者向けドキュメントのGoogle Drive APIのスコープを選択するを参照してください。

Googleドライブの統合

GoogleドライブとFire OSアプリを統合するには、まずA3L Authentication SDKを統合し、ログイン機能を実装する必要があります。手順については、A3L Authentication SDKの統合を参照してください。次に示すように、アプリのbuild.gradleファイルに依存関係としてGoogle Drive SDKを追加します。

implementation('com.google.apis:google-api-services-drive:<バージョン>')

google-api-services-driveのバージョンv3-rev20220709-2.0.0あるいはそれ以降を使用してください。

A3LSignInOptionsを作成するときに、requestScopes()メソッドを使用してGoogleドライブの適切なスコープをリクエストします。次のコードを参照してください。

A3LSignInOptions a3LSignInOptions = new A3LSignInOptions
.Builder(A3LSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(new Scope(DriveScopes.<スコープ>))
.requestEmail()
.build();

認証情報の作成

ユーザーがログインしたら、FOSAccountCredentialオブジェクトを使用してGoogleドライブの認証情報を作成します。このオブジェクトの作成時には、A3LSignInOptionsに渡したスコープと同じスコープを渡します。以下に例を示します。

FOSAccountCredential fosAccountCredential = new FOSAccountCredential.usingOAuth2(context, Collections.singleton(DriveScopes.<スコープ>));
fosAccountCredential.setSelectedAccount(account);

この認証情報を、次のようにGoogleドライブのビルダーで使用します。

Drive googleDriveService = new Drive.Builder(new NetHttpTransport(),
                            new GsonFactory(),
                            fosAccountCredential)
                            .setApplicationName("<アプリ名>")
                            .build();

これで、このDriveオブジェクトをGoogle Drive API呼び出しで使用できるようになりました。次のコードは、Driveオブジェクトを使用して、最大10個のファイルの名前とIDを一覧表示する方法を示しています。

FileList result = googleDriveService.files().list()
     .setPageSize(10)
     .setFields("nextPageToken, files(id, name)")
     .execute();
List<File> files = result.getFiles();
if (files == null || files.isEmpty()) {
  System.out.println("No files found.");
} else {
  System.out.println("Files:");
  for (File file : files) {
  System.out.printf("%s (%s)\n", file.getName(), file.getId());
  }
}

クラスの違い

次の表は、GoogleAccountCredentialクラスとFOSAccountCredentialクラスで使用できるメソッドの違いを示しています。

API GoogleAccountCredentialで使用可能 FOSAccountCredentialで使用可能
static usingAudience(Context context, String audience) ×
static usingOAuth2(Context context, Collection<String> scopes)
Constructor (Context context, String scope)
getAllAccounts()
ログインに使用されたアカウントのみを返します。
getBackOff()
getContext()
getGoogleAccountManager() ×
getScope()
getSelectedAccount()
getSelectedAccountName()
getSleeper()
getToken()
initialize(HttpRequest request)
newChooseAccountIntent() ×
setBackOff(BackOff backOff)
setSelectedAccount(Account selectedAccount)
setSelectedAccountName(String accountName)
setSleeper(Sleeper sleeper)

Last updated: 2023年12月5日