one_second_diary icon indicating copy to clipboard operation
one_second_diary copied to clipboard

Optional Google Login / Drive Backup

Open KyleKun opened this issue 3 years ago • 11 comments

KyleKun avatar Nov 29 '22 12:11 KyleKun

@Amorenew

KyleKun avatar Nov 29 '22 12:11 KyleKun

@KyleKun I want to start on this; can you please elaborate on this?

ishanvaghani avatar Dec 25 '23 04:12 ishanvaghani

@KyleKun I want to start on this; can you please elaborate on this?

In settings page, there's a backup tutorial button. This should become a backup feature instead, redirect to login with Google account and then sync the folder OneSecondDiary (inside DCIM) with Drive / Google Photos.

KyleKun avatar Dec 25 '23 11:12 KyleKun

And please remember not to use proprietary libraries. Otherwise F-Droid inclusion won't be allowed any more.

alexanderadam avatar Dec 25 '23 12:12 alexanderadam

And please remember not to use proprietary libraries. Otherwise F-Droid inclusion won't be allowed any more.

But in case it is unavoidable, we can keep a variant without it for f-droid.

KyleKun avatar Dec 25 '23 12:12 KyleKun

Sure, then the PR should allow a build condition to disable a build with the proprietary library. 👍

alexanderadam avatar Dec 25 '23 12:12 alexanderadam

We need to use Google Auth APIs and Drive APIs.

ishanvaghani avatar Dec 26 '23 03:12 ishanvaghani

We need to use Google Auth APIs and Drive APIs.

Using an API isn't a problem here. Using certain APIs might just be shown as a warning on F-Droid. But using a proprietary library will exclude the app from being published.

Right now I'm using Round Sync (which also supports Google Drive and other clouds for backing up btw) for automatic backups of One Second Diary clips. Round Sync is a fork of RCX and uses the free Rclone sync library.

And because it uses only free components, both apps can be published on F-Droid (RCX and Round Sync).

alexanderadam avatar Dec 26 '23 08:12 alexanderadam

User will need Round Sync app in this case. So it's dependency of the other app.

ishanvaghani avatar Dec 27 '23 03:12 ishanvaghani

@alexanderadam We could just use HTTP calls so we don't get warnings

Using certain APIs might just be shown as a warning on F-Droid. But using a proprietary library will exclude the app from being published.

amorenew avatar Dec 27 '23 03:12 amorenew

how to use Google login in Flutter without a library? import 'package:http/http.dart' as http; import 'dart:convert'; import 'dart:typed_data';

Future signInWithGoogle() async { // Define your Client ID and other configurations String clientId = 'YOUR_CLIENT_ID'; String redirectUri = 'YOUR_REDIRECT_URI'; String scopes = 'openid email https://www.googleapis.com/auth/drive.file'; // Include the Drive file scope

// Create the authorization URL String authUrl = 'https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=$clientId&redirect_uri=$redirectUri&scope=$scopes';

// Open a webview or use url_launcher to open authUrl in a browser // Capture the response after successful login and extract the authorization code

// Exchange the authorization code for an access token // Construct the POST request String tokenUrl = 'https://oauth2.googleapis.com/token'; String code = 'YOUR_AUTHORIZATION_CODE';

Map<String, dynamic> body = { 'code': code, 'client_id': clientId, 'client_secret': 'YOUR_CLIENT_SECRET', 'redirect_uri': redirectUri, 'grant_type': 'authorization_code', };

// Send POST request to exchange code for access token http.Response response = await http.post(Uri.parse(tokenUrl), headers: {'Content-Type': 'application/x-www-form-urlencoded'}, body: body);

// Parse the response to get access token if (response.statusCode == 200) { Map<String, dynamic> tokenData = json.decode(response.body); String accessToken = tokenData['access_token']; // You can use this access token to make requests to Google APIs } else { // Handle error } }

how to use google drive in Flutter without a library? import 'dart:convert'; import 'package:http/http.dart' as http;

Future uploadToDrive(String accessToken) async { String uploadUrl = 'https://www.googleapis.com/upload/drive/v3/files?uploadType=media';

// File content to be uploaded String fileContent = 'Hello, this is a test file content!';

// Create the HTTP request to upload the file http.Response response = await http.post( Uri.parse(uploadUrl), headers: { 'Authorization': 'Bearer $accessToken', 'Content-Type': 'text/plain', // Change content type based on your file type }, body: utf8.encode(fileContent), );

if (response.statusCode == 200) { print('File uploaded successfully!'); // Handle success } else { print('File upload failed: ${response.body}'); // Handle error } }

amorenew avatar Dec 27 '23 03:12 amorenew