Codenameone Connect to Google Drive - oauth-2.0

This may be a dumb questions, but I haven't found an answer after lots of searching. I need to do two things, I need to allow my app to login to google, then save a file the users google drive.
I've found some steps on how to connect to google drive, but either its outdated or I don't have the correct libraries because it fails to compile: https://www.codenameone.com/google-login.html
Any help would be greatly appreciated.

For the login part there are good instructions in this blog post
Another sample of code to login to Google in this demo
You'll need to set the scope of the OAuth2 login to the appropriate Google Drive Scope
For saving files to drive, you should use ConnectionRequest to create the HTTP requests directly to their REST API.

Check the Integrating Google Sign-In into your web app. There's even an video guide explaining the concept.
There's a quick Save to Drive which enables your web site to allow users to save files to their Drive account from an arbitrary URL via their browser. If that's not sufficient enough, you can always check the Uploading Files where you can upload file data by creating or updating a File resource.

Related

Upload files to google drive using Google.Apis.Drive.v3 in asp.net MVC

I want to upload files to Google Drive using the Google.Apis.Drive.v3 in asp.net MVC. I want my visitor to upload the files to my google drive, I will set the credentials of my google drive in code. Can anyone help me to get this work?
I tried the quick start sample for upload but it asks for the credentials every time. Or it uses the cached credential.
How can I upload a file without knowing the user about the credential?
According to this documentation, you need to get the access credentials to enable the Google Drive. If you want to programmatically access users data without any manual authorization on their part, then perform Google Apps Domain-Wide Delegation of Authority. To delegate authority this way, domain administrators can use service accounts with OAuth 2.0. You can also check on this link which might help.

Google Drive - Access Drive without consent form (Username/password known)

I've been reading on Google Drive's API which seems straight-forward enough, but I'd like to use it a bit differently.
Instead of a client-side application, I need to be able to batch copy files in a given directory on a server to a specific Google Drive account which I have control over. To elaborate, I'm implementing a scan-to-email feature in which a user can scan a document on our copier which is then copied to that Google Drive account.
This is done for internal users, so the accounts would be generic and there would be no reasons to change the passwords. Is this possible at all?
I would recommend you go with a service account. Think of a service account as a user, a service account will have its own drive account. You will be able to upload the files to it, and your application wont be required to login as it will have the login built into it. You will not be able to login and see the files for this account via the web interface.
In order for the users to access the files again you have a few options.
You can then set the permissions on the files to allow the different users to access the files via there google drive accounts. Google drive api permissions
you could create your own interface and use files list to list the files that are currently stored on the service account.
Heads up:
You will at some point want to know how much space the service account drive has left. use about.get
Google has a number of client libs that can make doing all of this quite easy. but you haven't said what language you are planning on doing this in.
You could rely on the insert method of the "File" resource within the API. This will allow you to create a Google Drive File with the file type based on the scanned file. Refer to this document for examples and further assistance: https://developers.google.com/drive/v2/reference/files/insert#examples
https://developers.google.com/drive/web/manage-uploads

Google Drive as a backend server without asking user to login

I am trying to build an iOS application that all users sharing the same google drive account. All users will access the same account to download content only. I am the only one who is uploading content to google drive on web. For this case, is it possible to skip the login and auth process for the user? It would be great if I can have the users directly download the content, and hopefully make the login and auth implicitly done by code.
Please help. Thanks in advance.

Google Drive API for iOS: OAuth2.0 with an application-owned account

I'm creating a simple iPhone app. The basic premise is that the app will display some data (That I provide online) on the application. The data changes over time, so the app has to draw the data from online and display it. I don't have a significant programming background so I don't want to use my own server.
Thus, I thought it would be significantly easier to just put the data into some documents on a Google account and then access them programmatically via the Google Drive API. I could then update the data in my Drive account and it would get updated in the application. The key here is that I am ONLY accessing ONE account that I own MYSELF. The users' accounts are not being accessed. Therefore the goal is to never have to log in manually. It should all happen behind the scenes, aka, it should look like a server, not a google doc.
With this in mind, it doesn't make sense to show the Google Accounts sign-in page to my users as the standard OAuth2.0 tutorial shows here:https://developers.google.com/drive/quickstart-ios#step_1_enable_the_drive_api
I should be able to access my own data by somehow hardcoding in my username, password etc. Google agrees here: https://developers.google.com/drive/service-accounts#use_regular_google_accounts_as_application-owned_accounts
The above link mentions a "refresh token" that I'm supposed to save. However, I have no idea how to build and save that token, or even for that matter, where to find it.
I've gone through both the basic tutorial and the Dr. Edit Tutorial for iOS, but they both assume that the application is accessing USER accounts not application-owned accounts.
I'm not asking for someone to write the code for me (though tidbits are nice), but if you can point me to a step-by-step guide or related sample code that would help me get started that would be awesome. I'll even come back and post the code that I use!
EDIT: Since I realized that the Google Drive API wasn't something I could use for what I am trying to do, I eventually found Parse which is an awesome tool that handles all the server backend for me and is free at the basic level.
Google APIs objective-C client library doesn't support service (application-owned) accounts, because they are supposed to be used by a server-side apps, instead of clients -- you shouldn't be distributing your private key as a part of an app.
If you would like to distribute content from a service account, maybe you should write a server leg to do the authentication and pass clients credentials in a secure way for them to talk to the API on the behalf of the service account. Or, use Web publishing to make documents universally accessible without authorization and authentication if privacy is not a concern.

Need Help Concerning iOS + Google Drive

What I want to do:
I need my ipad/iphone app to save files (image, pdf..etc) to a central google drive account
(note this app will be distributed to several clients, but all app will use same google drive account)
What I have done so far:
got hold of the google drive examples and sources
made a new test project, included the libraries required, build works fine
Problem:
All examples seem to use controlers/views to authenticate and use credentials from keychain.
In my case, I want to hardcode the email and password, do the authentication in the background and then push the files to Google Drive.
I have not found some good pointers or explanation as to how to achieve this and the sample code provided by google seems to be a whole mess..
I'm having a hard time to figure this out.
Well this seems to be quite impossible as the credentials and access token are obtained from the user always and the new Google Drive SDK does not support to what you want. And O-Auth will also not support you as its against their policy of User Data Protection.
You could try a call like this, following the same process as in the Google Example commenting out the part where the viewController is pushed to the front
[webView stringByEvaluatingJavaScriptFromString:#"document.getElementById('Email').value='ur.email#gmail.com';"];
[webView stringByEvaluatingJavaScriptFromString:#"document.getElementById('Passwd').value='urPass';"];
[webView stringByEvaluatingJavaScriptFromString:#"document.getElementById('signIn).click();"];
I glanced at the code for the google signin page and it gave these names for the text fields and for the "go" button

Resources