I want to generate access token for my google drive and want to use that access token for creating folders in my google drive.
For folder creation I have written working code only issue is I am not getting access token for it.
Can anyone please tell me how to get access token by using apex class and trigger
Thanks
Related
Below was my original question, but I have tried several queries, and finally got closer to fixing the problem.
Following the tutorial, I have managed to access the BigQuery from Google Apps Script, but it gives "Permission denied while getting Drive credentials" error when the query contains GoogleSheet linked table.
As BigQuery gives an option to create the table linked with GoogleSheet, I have several tables in this setting.
A query without linked table works, so the basic setting for the code is fine, and I believe the credentials setting is in BigQuery.
I do have the access to the GoogleSheet which is linked in BigQuery.
If anyone has an idea how to fix this, I would very much appreciate it.
I am trying to access BigQuery from Google Apps Scripts, and going through the tutorial in the link below.
https://developers.google.com/apps-script/advanced/bigquery#run_query
I have managed to run script in the tutorial, so moved on to access my own dataset where I get the error as below
GoogleJsonResponseException: API call to bigquery.jobs.query failed with error: Access Denied: BigQuery BigQuery: Permission denied while getting Drive credentials.
For python, there is samples where you can add the local file like service_account.json which has all the credential data. GAS has appsscript.json, but this seems to be in different format.
Is there anywhere else I can set the credentials?
BigQuery and Google Apps Script is owned by the same google user, so the access from chrome browser is granted.
Got the same issue with my Google Apps script. Steps to fix:
Enable Google Drive API under 'Services'
Add DriveApp.getRootFolder(); in the beginning of your project/function to get Drive Auth Scope.
Should work!
I was using google sheet from one application using htttp request like https://script.google.com/macros/s/XXXXXXXX/exec
but now Google has changed the access method. now I cannot access the URL mentioned above (XXXXXXXX : Replaced with my sheetid).
Now I was searching the access method and I found that we can also access using google API keys. which has to send in the HTTP request. Here is the page for more information.
https://developers.google.com/youtube/v3/guides/auth/server-side-web-apps#httprest_1
But I am not getting a complete idea for HTTP request.
Anyone has tried the same or related.
From the question
I was using google sheet from one application using htttp request like https://script.google.com/macros/s/XXXXXXXX/exec but now Google has changed the access method. now I cannot access the URL mentioned above (XXXXXXXX : Replaced with my sheetid).
The XXXXXXXX is not the the sheetid, it's a unique id assigned to the corresponding web app deployment.
To get the web app full URL you have to go to your script, using the new Google Apps Script IDE, click on Deploy > Manage Deployments then select the corresponding deployment.
Resources
https://developers.google.com/apps-script/guides/web
What I trying to do here is an application that connects to bigquery, executes some query and writes a spreadsheet in current user's Google Drive.
I know that I can change the "Execute app as" option when deploying the app. But when I do this, and the user try to use the app, Google asks for permission to access the BigQuery.
I do not want to give permission to each user to access BigQuery.
We have about 50 ~ 100 users who will use (and this number can increase)
Some images:
When access the application's url: http://i.imgur.com/kGzJ3ps.png.
When the user clicks in the "continue" button:
http://i.imgur.com/4cRmhZ6.png
Hope I've been clear.
You would probably need an App, that had people sign in with their Google account using oAuth2
Google Accounts Authentication and Authorization
I think that this link gives an overview of what your options are:
Permissions and Types of Scripts
I guess you would need to have an App, that ran as User at the keyboard, so that the spreadsheet saved to their Google Drive. If you wanted the user to be able to download a file to their computer drive, that's a little different.
Just use HTML Service. It's basically just building a website. You just don't have a domain name. But the spreadsheet you are distributing doesn't have a domain name.
HTML Service Google Documentation
From an Apps Script HTML Service, you can write to Spreadsheets, Documents, and run HTTP Requests (urlFetch).
URL Fetch Service
The permissions in the Apps Script App can be set to run the Apps Script file as yourself, with access to anyone, even anonymous. That way, the user will never be asked for permission for any files that you own. You will need to authorize it once, the first time any script that needs access to your files is run.
Because anyone could run your Apps Script App, you might want to have a log in system to authenticate users.
You would need to use the Big Query API with Apps Script urlFetch to access Big Query.
So, with the HTML Service, you can do most everything you could do with HTML, CSS, and Javascript on a regular website. You can create custom input forms, have different pages and display data in tables. Plus it's served over HTTPS.
One solution that you can use if you don't want all your users to enable BigQuery is to use a webapp deployed as a service running as "you" and that will respond to an urlFetch coming from each user through the script they run as "themselves".
This service will be deployed as any other webapp using a doGet main function and return its data using contentService
Yes, that is possible. Check out this answer here: Using Advanced Google Services with Service Account and also check this awesome library: https://github.com/googlesamples/apps-script-oauth2
I am writing an application that can modify an spreadsheet in Google Drive, but the problem is that each time I try to access Drive contents it asks for access token as per the OAuth2 specification which I have to generate manually after browsing through the following link:
https://accounts.google.com/o/oauth2/auth?access_type=online&approval_prompt=auto&client_id=<THE_CLIENT_ID>&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=https://www.googleapis.com/auth/drive
Anybody having idea if its possible to either get this token through Drive API or through any other medium, The client application will be in the form of a Java Swing application in which there will be text fields the text inserted in those fields will be added as a row in the spreadsheet hosted on the Google Drive.
Thanks
You need to get the token manually the first time, but then you can reuse it. I guess this is a duplicate?
Stored Credential from google api to be reused java
must I click "Allow Acess" every time I connect? Google Drive SDK API
[EDIT] Sorry, I did not see the date.
I am trying to authorize files on my google drive with specific APP authorization I created. As files on my google drive can only be manipulated by its authorized app, is there any way I can convert these "None" authorized file with APP authorization? And, if yes, by which function?
I looked all over the tutorial document but only find discussion about permission. The only method I can think about is uploading these files to google drive with upload function from my created app. But I guess there is a much smarter way. Do any one has the same experience?
Here list my steps to create authorized file:
First, I start my app from using sample code, DrEdit. https://developers.google.com/drive/examples/python;
From the code, I successfully open new files and saw them listed on my google drive.
From view authorized app, I can clear see these apps created from my app have their authorization signed with app ID. The other files original belong to me have these authorization signed as "None".
I had the same issue and had to change the scope from https://www.googleapis.com/auth/drive.file to https://www.googleapis.com/auth/drive which gives full access to all drive files rather than just the ones created by the app.