Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional Google Login / Drive Backup #29

Open
KyleKun opened this issue Nov 29, 2022 · 11 comments
Open

Optional Google Login / Drive Backup #29

KyleKun opened this issue Nov 29, 2022 · 11 comments
Labels
enhancement New feature or request

Comments

@KyleKun
Copy link
Owner

KyleKun commented Nov 29, 2022

No description provided.

@KyleKun KyleKun added the enhancement New feature or request label Nov 29, 2022
@KyleKun
Copy link
Owner Author

KyleKun commented Nov 29, 2022

@amorenew

@KyleKun KyleKun added the TODO - v2.0 Next big version. No ETA. label Dec 27, 2022
@KyleKun KyleKun removed the TODO - v2.0 Next big version. No ETA. label May 25, 2023
@ishanvaghani
Copy link

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

@KyleKun
Copy link
Owner Author

KyleKun commented Dec 25, 2023

@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.

@alexanderadam
Copy link
Contributor

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

@KyleKun
Copy link
Owner Author

KyleKun commented Dec 25, 2023

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.

@alexanderadam
Copy link
Contributor

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

@ishanvaghani
Copy link

We need to use Google Auth APIs and Drive APIs.

@alexanderadam
Copy link
Contributor

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).

@ishanvaghani
Copy link

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

@amorenew
Copy link

@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
Copy link

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
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants