|
Post by metro on Jul 21, 2020 19:07:45 GMT -5
Has anyone tackled uploading files to Google drive using LB. I would like to automate the process of uploading a *.PDF and then creating a share link.
Any help appreciated...
metro
|
|
|
Post by Chris Iverson on Jul 23, 2020 2:20:31 GMT -5
Just started reading through Google's API for accessing Drive, and oooooh boy, what an undertaking that would be.
I won't say it's impossible in LB, but it would be a LOT of work, and require a good bit of knowledge to implement various protocols to handle the transfer successfully.
|
|
|
Post by metro on Jul 23, 2020 3:10:49 GMT -5
Just started reading through Google's API for accessing Drive, and oooooh boy, what an undertaking that would be. I won't say it's impossible in LB, but it would be a LOT of work, and require a good bit of knowledge to implement various protocols to handle the transfer successfully. Thanks for taking a look Chris, I started looking for other options too. Seems there are programs that will Sync with Google Drive. So I think that maybe my best option although I expect the free versions will have limited capability.
If it is daunting for you I am fairly certain my old brain will not grasp it.
metro
|
|
|
Post by tsh73 on Jul 23, 2020 13:41:56 GMT -5
Google search for "command line Google drive client windows" has turned this (recommended on stackexchange.com, superuser.com) github.com/gdrive-org/gdriveI haven't tried it though.
|
|
|
Post by metro on Jul 24, 2020 2:50:10 GMT -5
Google search for "command line Google drive client windows" has turned this (recommended on stackexchange.com, superuser.com) github.com/gdrive-org/gdriveI haven't tried it though. Thanks Anatoly, I'll have a bit of a play with that.
more than one way to skin a cat
|
|
|
Post by Carl Gundel on Jul 24, 2020 12:55:49 GMT -5
Just started reading through Google's API for accessing Drive, and oooooh boy, what an undertaking that would be. I won't say it's impossible in LB, but it would be a LOT of work, and require a good bit of knowledge to implement various protocols to handle the transfer successfully. Is there some clever way for LB to generate a web page and open a browser on that page to automate this task?
|
|
|
Post by Chris Iverson on Jul 24, 2020 13:36:41 GMT -5
Using just browser code, i.e. HTML and/or Javascript, absolutely not. If there was, all major browser engines would consider that a cross-site scripting(XSS) vulnerability and shut it down hard.
If someone could generate and open a local browser page to do that, what would stop them from, say, making a similar page that instead uploads all of your private files to THEIR Google Drive?
Or, stepping out to other websites, loading and stealing all of your banking information? Logging into Paypal and sending themselves a bunch of money? Making a bunch of fraudulent purchases on Amazon?
You might be able to do something like automate mouse movements to do the upload, but I think that would be even more work than using the regular GDrive API, and more fragile, too, since you'd need to change it every time they changed the website, unlike the API, which is a backend API that would stay the same for years.
The gdrive command-line tool is interesting, although a bit clunky to use completely by itself due to needing manual user input to login/authorize. There are command-line options for providing access/refresh tokens; I wonder if some form of combo can be used with LB initiating a more proper authorization path, and then utilizing gdrive to handle the actual uploads.
|
|
|
Post by Rod on Jul 24, 2020 14:13:10 GMT -5
I know little of what you guys are talking about. However there is a recent thread talking about ATL controls where we can open a browser and point it at a local html file and it will happily open and display. What it won’t do is interact with the user. For that we would need some of the magic behind Run BASIC and have a local server. libertybasiccom.proboards.com/thread/642/python-emperors-new-clothes
|
|
|
Post by meerkat on Jul 24, 2020 14:17:56 GMT -5
Howdi Laurie.. I ran across this for html.
I tested it a little. Don't have a google account, and don have time to set up a account and test right now. So decided to post it if anyone is interested. I'll try to finish it up later. It's in Run Basic. So for whatever it's worth here it is:
' ' Add buttons to initiate auth sequence and sign out--> ' html "<button id='authorize_button' style='display: none;'>Authorize</button> <button id='signout_button' style='display: none;'>Sign Out</button>
<pre id='content' style='white-space: pre-wrap;'></pre>
<script> // Client ID and API key from the Developer Console var CLIENT_ID = '<YOUR_CLIENT_ID>'; var API_KEY = '<YOUR_API_KEY>';
// Array of API discovery doc URLs for APIs used by the quickstart var DISCOVERY_DOCS = ['https://www.googleapis.com/discovery/v1/apis/drive/v3/rest'];
// Authorization scopes required by the API; multiple scopes can be // included, separated by spaces. var SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly';
var authorizeButton = document.getElementById('authorize_button'); var signoutButton = document.getElementById('signout_button');
/**************************************************************\ * On load, called to load the auth2 library and API client library. \**************************************************************/ function handleClientLoad() { gapi.load('client:auth2', initClient); }
/**************************************************************\ * Initializes the API client library and sets up sign-in state * listeners. \**************************************************************/ function initClient() { gapi.client.init({ apiKey: API_KEY, clientId: CLIENT_ID, discoveryDocs: DISCOVERY_DOCS, scope: SCOPES }).then(function () { // Listen for sign-in state changes. gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
// Handle the initial sign-in state. updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get()); authorizeButton.onclick = handleAuthClick; signoutButton.onclick = handleSignoutClick; }, function(error) { appendPre(JSON.stringify(error, null, 2)); }); }
/**************************************************************\ * Called when the signed in status changes, to update the UI * appropriately. After a sign-in, the API is called. \**************************************************************/ function updateSigninStatus(isSignedIn) { if (isSignedIn) { authorizeButton.style.display = 'none'; signoutButton.style.display = 'block'; listFiles(); } else { authorizeButton.style.display = 'block'; signoutButton.style.display = 'none'; } }
/**************************************************************\ * Sign in the user upon button click. \**************************************************************/ function handleAuthClick(event) { gapi.auth2.getAuthInstance().signIn(); }
/**************************************************************\ * Sign out the user upon button click. \**************************************************************/ function handleSignoutClick(event) { gapi.auth2.getAuthInstance().signOut(); }
/**************************************************************\ * Append a pre element to the body containing the given message * as its text node. Used to display the results of the API call. * * @param {string} message Text to be placed in pre element. \**************************************************************/ function appendPre(message) { var pre = document.getElementById('content'); var textContent = document.createTextNode(message + '\n'); pre.appendChild(textContent); }
/**************************************************************\ * Print files. \**************************************************************/ function listFiles() { gapi.client.drive.files.list({ 'pageSize': 10, 'fields': 'nextPageToken, files(id, name)' }).then(function(response) { appendPre('Files:'); var files = response.result.files; if (files && files.length > 0) { for (var i = 0; i < files.length; i++) { var file = files[i]; appendPre(file.name + ' (' + file.id + ')'); } } else { appendPre('No files found.'); } }); }
</script>" html "<script async defer src='https://apis.google.com/js/api.js' onload='this.onload=function(){};handleClientLoad()' onreadystatechange='if (this.readyState === 'complete') this.onload()'> </script>"
|
|
|
Post by metro on Jul 24, 2020 19:19:45 GMT -5
Thanks Dan, I'll give it a good crack. I'm glad this post Piqued the interest of a few here, some interesting concepts thrown up. PS I'll have a Cooper's for ya tonight Dan, I've lost count of how many I owe you. Hope ya kept ya shirt after ya last trip to Vegas.
|
|
|
Post by metro on Jul 24, 2020 20:25:41 GMT -5
I tried Dan's runbasic code, however it was without my client ID and API_KEY and received the following pasting the link console.developers.google.com/ in my browser I was immediately recognised and my Google account was displayed there seems to be far too many hoops to jump through to create and register (with Google) a simple upload program. I'll tackle it again when I get some time. Thanks Dan.
|
|
|
Post by meerkat on Jul 24, 2020 20:52:08 GMT -5
Yep.. Had lots of fun in Nevada and still have my shirt.. Sorry I don't know anything about google drive, but ran across this. Is this anything you can use?? developers.google.com/drive/api/v2/reference/files/copyIt's 7PM here, I have shrimp on the barbie, so here's a Tooheys New to you.. Hope this helps. Dan
|
|
|
Post by Chris Iverson on Jul 25, 2020 1:57:08 GMT -5
Yeah, Google takes access to their services seriously.
First, you can't just take a username and a password from the user. They don't want people collecting passwords, and that may not be enough anyway, if the person has multi-factor authentication enabled, which you have no way to collect.
So, you have to ask the user to approve your application to have access to their data.
This means you have to register the application with Google. (That's what's done on that developer page.)
When you register the application, you'll get a unique token for your application to use. When making the request for approval, that token will identify that it's your application that wants access.
To actually make the request for approval, you send the user to a specific Google page that will ask them to log in(if needed) and to approve your application for access to their data. When they approve, depending on how the authorization is set up, the user will either get a bit of data to write or copy/paste into your application, or the user will be auto-directed to a website(or temporary local webserver) that automatically receives the approval token.
The approval token can then be used to make various requests against the user's account, such as accessing or uploading data. There ARE restrictions on what data can be accessed, and depending on what you need to access, you may have to submit your application to Google for approval before you can make a public release and use it outside of limited self-testing.
(This last step is what the API you linked to is used for, meerkat; it's what you use to interact with Google's systems once you have the user fully authorized. Though I would personally use the latest version of the API, v3.)
Just uploading files and managing permissions on the files uploaded by the program to make a sharable link shouldn't need this kind of approval, but if you're touching data on the account that your app didn't put there, you're likely going to hit a restriction.
The reason for all of this complication is protection of the user's data AND the user's private information. Under this model, the application accessing the user's Google account never even sees the user's password. This is important in preventing credential stealing; you can't steal something if you never have it in the first place.
And by having per-application authorization made explicit to the user, they can revoke access to your application at any time. Google can revoke access to your application entirely by invalidating your registration token; the user can invalidate your application's access to their account by invalidating the user access token. The tokens also expire after a while, and can be replaced at any time. (I believe there's a window where the application can silently request a new one; they actually get two tokens, an "access token" and a "refresh token". If neither token is still good, then the user must authorize the application fresh from the beginning again.) Having the tokens expire means that, even if it's stolen to be used by someone else, it will only be active for a short while.
It's a royal pain, but it's also an unimaginable boon to the safety and security of Google's users.
|
|
|
Post by metro on Jul 25, 2020 3:36:03 GMT -5
Thanks Chris, from the outset the idea was to
create a PDF within my desktop application
upload it to MyGoogeDrive (directly, programmatically or with file syncing program)
SMS or email the link to a customer or download it.
I'll keep plugging away....... metro
|
|
bart
New Member
Posts: 7
|
Post by bart on Aug 9, 2020 3:51:34 GMT -5
Would using "Backup & Sync by Google" be a solution? That's how I upload to Drive (and similarly for Dropbox) using LB.
Or if you're generating the PDF with LB, save to your Drive folder? Otherwise use 'name'. e.g. name "c:\temp\test.pdf" as "D:\Users\Bart\Google Drive (xxx@gmail.com)\test.pdf"
|
|