google-drive-sdk : call google-drive-sdk - google-drive-api

I am new using google scripts and drive-sdk.
I'd like to call the copy functionality of drive-sdk. When I try it, I get a message that says I need authentication.
Where can I find an example of how can I authenticate from a google script to authenticate de drive-sdk?
Thanks in advance.
Biagio

Have a look at the Google's Drive SDK docs regarding authentication.

https://developers.google.com/drive/quickstart-php is a good example in PHP. other languages they have quickstart examples for: Java, Python, .NET, Ruby, Javascript, Go, and Objective-C/iOS

First, view Google's information on authorising with the Drive API.
Then, choose which language you wish to use, I would reccomend JavaScript (or Node.js) if you want to play around or are making a web app.
If you wish, you can view a simplified explanation of the OAuth2.0 flow.
To clarify, the basic steps you can use to get going in JavaScript (as an example) are:
View this official Google getting started page
Set up the Drive API in the Google Developers Console
Copy the code from the getting started page
Ensure you place your ClientID from the Google Developer console into the copied code
Install Python if you haven't already (version 2 or 3)
Start the web server using Python (python -m SimpleHTTPServer 8000 for version 2) and load 'http://localhost:8000/quickstart.html' into your web browser

Related

How to retrieve my Install Statistics from the Google Developer's Console

I am trying to programmatically retrieve my company's app data from the Google Developer's Console, specifically the daily installs. I have found that Google recommends the gsutil tool to access the data programmatically through the Google Cloud Storage SDK. However, I beleive they charge for this service. I want a free way to programmatically retrieve the data, preferably as a JSON stream to avoid dealing with file downloads. I have found the "direct reporting" links, but I have problems authenticating when I try to use them, and I also have to do something with the actual files then.
Is there a way to get a JSON version of the data through OAuth2 or something without downloading an Excel file? Has anyone had to do this?
You should look into use the Core Reporting API.
There are client libraries available in a number of languages.
You should work through the Hello Analytics APIs to get started.
Java Script
PHP
Python
Java
A quick solution for building a dashboard would also be the Embed API.
Using the gsutil tool to access the company's storage bucket that are provided by google is a free service. I wrote a code that will run the gsutil code as a process through the command line and parsed the downloaded .csv files into a database for storage. OAuth2 was not necessary.

Accessing Google Drive SDK from Perl

I have couple of Perl scripts that uploads / reads files from Google drive. Is it possible to access Google drive with Perl Api, or I need to switch to python or some scripting languages that Google supports.
We have a REST API. You can use any language to implement your own client, you don't have to use one of the client libraries we support.
An overview of the resources are here: https://developers.google.com/drive/v2/reference
Auth is explained on https://developers.google.com/accounts/docs/OAuth2#webserver
File upload is explained on https://developers.google.com/drive/manage-uploads
I just found a nice cpan module for talking to Google drive. So it might be as useful to you as it will be to me, because I just started playing with it. The only thing that is weird about it is that it needs to run install script to create the initial credentials on your machine.
http://search.cpan.org/~mschilli/Net-Google-Drive-Simple-0.03/lib/Net/Google/Drive/Simple.pm#SYNOPSIS

Confuse after quickstart

I am pretty new to Google Drive SDk. After spend hours on the google drive sdk document and quick start app, I think I have known some basic concepts about it.
However, I have a easy but crucial question: how to integrate my code with Drive UI.
I mean I know I should enable Google Drive API and Google Drive SDK and do some configure staff. And I did.
I set up the MIME type that my app should be able to open and create, but it doesn't work. (I used the most easy one: plain/text: txt).
In fact, I think this is not the most serious problem. I am confused about how to integrate my code with Drive UI.
I mean the quick start app works fine, but it just simply upload a file. What if I want to perform some complicate action after user open a certain file with my app?
Ideally, I think it should redirect the user to my open URL and all the actions should go with that site, right?
(I am using Python, in case that could make any differences)
I am really confused. Excuse my chaos description, please.
Thanks in advance!
EDIT:
Thanks for the answering below! I think I need to detailed explain my needs from google drive sdk.
Basically, I want the user who have installed my app be able to open a certain file (which should be spreadsheet or txt) on google drive. Then it will redirect the user to my given Open URL (which I create a site by using google site). On that site, user should be able to view and import the content of file into a certain database. None of the operations above require any technique knowledges. I certainly can do this by writing python script and run it locally to import the content of files on google drive. However, there are two issues: first, I need to run it locally. I mean I did use the google drive api, but I didn't explore the real benefit of api; second, it is still a command line script, and has to be ran on linux.
I hope I have illustrated my request. And I appreciate any help in advance!
Install the client library:
pip install --upgrade google-api-python-client
Acquire an access token as explained on the Python Quickstart example. Init a Drive service to be able to talk to the API and authorize http transporter with your credentials. You need to make requests to get file metadata and file contents.
Retrieve file metadata:
http = httplib2.Http()
http = credentials.authorize(http)
drive_service = build('drive', 'v2', http=http)
f = drive_service.files().get(fileId=file_id).execute()
Retrieve file contents:
downloadUrl = f.get('downloadUrl')
f['content'] = drive_service._http.request(downloadUrl)
(Don't forget content retrieving request should be authorized and authenticated, that's why we use drive_service._http to make that request.

App built using Google Drive PHP SDK keeps redirecting to the same page

I'm following this guide to create a sample web app which implements the Google Drive PHP SDK.
When I access the URL, the app keeps redirecting to the same page in an infinite loop, so no content is shown actually. Any idea why this is happening? Is it due to some mistake I made in the config file?
The document says how to implement the sample app - called DrEdit - as a Google Chrome application. Can anyone tell me if it is possible to use the SDK for creating non-Google Chrome apps? Also, does anyone have any example implementation of the Google Drive SDK?
If you provide more information and code, we can debug your first issue.
Otherwise:
Yes, you can write apps for Drive that are not Chrome apps. Chrome Web Store is an optional distribution mechanism for the API. Your apps will work in any browser.
There are documented PHP snippets for every API method, e.g. https://developers.google.com/drive/v1/reference/files/get

I am facing "The authenticated user has not installed the app with client id" error even after installing the app [duplicate]

I'm working on a Google Drive interface for Emacs. The concept is that Emacs could provide a platform-agnostic way to load, modify and save text documents stored in Google Drive. I've registered my app and can authenticate with OAuth2 and get a file listing with the Docs List API, but when I try to execute an Insert with the Google Drive API, I see an error:
"The authenticated user has not installed the app with client id ..."
Reading further, it seems I need to publish my Emacs application in the Chrome Web Store to get access to the Drive API. That doesn't make sense to me...I noticed that there is a FUSE project in development for Google Drive, which suggests that native development is possible. When I skimmed the code, however, I didn't see a Chrome Web Store component to getting it working.
Am I trying to misuse the API, or is there an route to make this work that makes more sense?
EDIT:
According to Ali Afshar, of the Google Drive team, installation is no longer required to use this API. So what follows may no longer be relevant, but will be left for historical purposes.
So, first off the API does not support application development in the sense that we are both doing it, I wouldn't use the word native though. The good news is I have been doing some research and Google Drive is really just a rebranding of Google Docs. So the Google Docs API could be a good choice as well for the same purposes.
Anyway, here's the steps to solve the error: "The authenticated user has not installed the app with client id ..." Which is a 403 error, for the sake of this answer. These steps assume you have set up an app in the chrome web store as is required, and installed it. I am working on my local machine too, with my project: http://github.com/tom-dignan/gdrive-cli which I have gotten past this error, so I think you should keep plugging away at your emacs version, because I think we can make this work.
a. Open the Google APIs console.
b. Confirm you've already enabled the apis under "API Access" both the API and SDK for Google drive should be enabled. There you get your client secrets/api keys and such. I am almost positive you've done this already, so go ahead to C. (this is here for others who may have missed it)
c. In the left navigation bar, under "Drive SDK" you will need to do the following:
Add a "Support URL" (required)
Add at least a small 16x16 application icon (required)
Add "OAuth Client ID (Required)" under Drive Integration (I was just tinkering and this seems to be the key field.)
Add "Open URL (Required) URL to open for your app from the google drive UI."
Check off "Multiple File Support"
Add some MIME types and file extensions, "text/plain", and txt for example
Add the the auth scopes:
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/userinfo.profile
Don't bother trying to add the auth scopes for Google Docs here, because it won't work. Google does not want us to use it that way because files that drive apps create should be private to that app. Integration with Google Docs will have to be separate.
Now I know you must be thinking "why do I have to add some of these..." It's because the form makes them required fields. In mine, I put a couple URLs that point to static HTML pages.
Once you've done the above, clean up your state and reinstall your chrome app. Then try your code again, and it should stop giving you a 403.