React Native OMH Storage - Google Drive (GMS / non-GMS)
Prerequisites
Before starting the integration, make sure the following packages are installed and configured:
@openmobilehub/storage-core
react-native-file-access
@react-native-async-storage/async-storage
react-native-app-auth
- Configuration@openmobilehub/auth-core
- Configuration@openmobilehub/auth-google
- Configuration
Installation
npm add @openmobilehub/storage-googledrive
Console App
To access Google Drive APIs, follow these steps to obtain the Client ID:
- Create a new app in Google Cloud console.
- Create an OAuth 2.0 Client ID Android application and specify your app's Package Name and SHA1 Fingerprint.
- Enable Google Drive API.
Secrets
To securely configure the Google Drive storage provider, add the following entry to your project's local.properties file:
GOOGLE_CLIENT_ID=<YOUR_GOOGLE_CLIENT_ID>
Usage
Initializing
To interact with the Google Drive storage provider, start by initializing the OMH Auth Client. Once the authentication client is set up, you can then initialize the OMH Storage Client.
import GoogleAuthClient from '@openmobilehub/auth-google';
import { GoogleDriveStorageClient } from '@openmobilehub/storage-googledrive';
const scopes = [
'openid',
'profile',
'email',
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/drive.file',
];
await GoogleAuthClient.initialize({
android: { scopes },
ios: {
scopes,
clientId: '<YOUR_GOOGLE_CLIENT_ID>',
redirectUrl: `com.googleusercontent.apps.${
'<YOUR_GOOGLE_CLIENT_ID>'.split('.')[0]
}:/oauth2redirect/google`,
},
});
const googleDriveStorageClient = new GoogleDriveStorageClient(GoogleAuthClient);
Other methods
Interacting with the Google Drive storage provider follows the same pattern as other storage providers since they all implement the IStorageClient
interface. This uniformity ensures consistent functionality across different storage providers, so you won’t need to learn new methods regardless of the storage provider you choose! For a comprehensive list of available methods, refer to the Getting Started guide.
The methods downloadFile
and downloadFileVersion
do not support Google Workspace documents (Google Docs, Google Sheets, and Google Slides). To download Google Workspace documents, please use the exportFile
method to export the file to a supported format.
The method createPermission
will override sendNotificationEmail
parameter to true
when creating permission with owner
role.
The method updateFile
does not support Google Workspace documents. It throws an error for Google Sheets and Slides and for Google Docs, it does not update the metadata (apart from file name) which can lead to unexpected behavior.
License
- See LICENSE