To Check google site access permission from App Script - javascript

Is it possible to check whether one have access to Google site using the site url in Apps Script?
My requirement is that when someone clicks on google site link and if they don't have access then they should be redirected to custom Access denied page.
I tried using UrlFetchApp but it didn't return anything relevant in order to distinguish whether one has the access to google site or not.
Please help!

Finally SitesApp.getSiteByUrl(link) helped to resolve my issue. If it throws an exception that means user don't have access to the site.
Documentation

Related

Grabbing data necessary for Oauth2 google using chrome extenion identity.

My question is how to grab the the correct information from the developers console and than apply that to my chrome extension. So far i understand that permission "Identity" need to be included within the manifest. Also that oauth2 with client_id and scopes also need to be added.
https://developer.chrome.com/extensions/app_identity#update_manifest
The website itself explain to grab the client id within the old versions of the website.
Information that i need to acquire from developers website:
API_Key
Scopes
Key
If possible i would liked further advice concerning the js to be able to grab the usernames first and last name and other ability such as google drive document creation or edits.
I've found a wizard on google api site
https://developers.google.com/drive/v3/web/quickstart/js
That gives me all the information i need <3

Can't POST FormData to a Google Sheet, would like to restrict access to people invited to edit the spreadsheet

I have a simple page with a form, and I decided to offer the option of submitting it to a Google Sheet. It's meant as part of an internal webapp, used by a few collaborators to submit to a spreadsheet shared between us. I would have used a Google Forms but I wanted more control over the form.
I have set up a Google Apps Script bound to the spreadsheet following these instructions and deployed it as web app with:
Execute the app as: Me
Who has access to the app: Anyone, even anonymous
This works fine, I can POST FormData with XMLHttpRequest (vanilla javascript). But so can anyone else, no matter if they're allowed to edit the spreadsheet, even if they're logged out of Google.
I'd like to restrict access to the web app - only people invited to the spreadsheet should be able to use the web app to insert rows. (Which is what I expected in the first place... if you don't have edit permissions you don't get to edit, period.)
At the moment switching the Google Apps Script Deploy as web app settings to anything else results in an 'Access-Control-Allow-Origin' error. I probably have to do something else - either in my page or in the GAS - to handle auth, right?
I want the web app to be deployed as
Execute the app as: User accessing the app
Who has access to the app: Anyone
and when a spreadsheet collaborator visits my page, he can submit the form - provided he's logged into Google.
the google apps script execution api does what you need. its well explained in the official docs:
https://developers.google.com/apps-script/guides/rest/api
its too broad to explain here step by step. you might need to read also about how to make an oauth2 flow from browser javascript.

Embed Google Analytics on thrid-part website

Trying to embed GA report on a third-part website, and I follow the Demo on Google Developers website, although I have some (silly) questions and I'm having trouble figuring it out.
After got clientid and put it my page I got exactly the same page as in google's example.
When I sent the link to someone else, it grabbed the info from the properties from people's GA I sent the link to, not my website.
Can someone help me set the property and eliminate the dropdowns to choose Account, Property, Views?
Thanks,
What you're asking is to do user authorization server-side. This will allow you to show Google Analytics data on your website without requiring your visitors to log in.
You can view the Embed API Service-Side Auth demo to see a working example.

Google Apps Script - How can i get the content of a page?

When i try to use the XMLHttpRequest() function in a google script, i get an error telling me the element is undefined.
Is there another way to get the content of a page using google script.
Any help would be much appreciated.
This is limited to avoid the ability to redirect people visiting a publicly (and trusted) document which would fetch data accessible on your browser (using your login sessions and etc).
Make sure you set the CORS headers as specified in the W3 specification to allow external services to query your request handler.
See the page here for more limitations: https://developers.google.com/apps-script/guides/html/restrictions#xmlhttprequests_xhr

Access an iFrame with JavaScript in Google Sites

I'm currently working on a Gadget which displays comments, via google docs spreadsheet, on my Google Site. I want the Gagdet to automaticly fetch the Username of the currently logged in User and parse it automaticly in the field "Name:" of the Gadget. I've tried with JavaScript to get the name with the span id, but JavaScript doesn't allow you to acces an external iFrame from another domain. My question is, is there any possibility to get informations about the logged in user? Maybe with the Google API or any other ways with JavaScript.
As you said, this is not possible, getting contents if Iframe from outside is permission denied. But there are some APIs from google that will let you see some information from logged in user. But you need to have permission:
GET https://www.googleapis.com/plus/v1/people/{userId}
or
https://www.googleapis.com/plus/v1/activities/z12gtjhq3qn2xxl2o224exwiqruvtda0i?key=YOUR-API-KEY
For more information have a look at https://developers.google.com/+/api/

Categories