Access an iFrame with JavaScript in Google Sites - javascript

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/

Related

To Check google site access permission from App Script

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

How to Upload File to Google Drive via a Web Form Anonymously

I need to implement a bug reporter form that users will be able to fill the form with additional information. Then this information will be posted to my google drive account as a text file.
I don't want users to be disturbed by any google drive or gmail permissions. I simply want my code to write file to my drive folder anonymously.
I made some investigation and I came up with google scripting as mentioned here. I created a custom web form to be filled and necessary gs(I guess this extension stands for google script) file.
I will not be able to add this form as an iframe because of cross domain, its url is something like 'https://script.google.com/macros/s/AKfycbxx...'. So I decided to open this form as a child browser tab, but that way I won't be able to pass bug message from parent to child.
Is there any way to send message from parent to child in this situation?
Is there any better way to implement this?
Thanks,
Ugurcan
you are on the right track. using an apps script webapp is an easy way to avoid all the oauth permission code. I assume you have published to run "as me" with access to "everyone even anonymous".
there is no need to open as a child window. Simply pass all the data you need as url parameters to your webapp.
then on your app the parameters are received in doGet and use them to populate form fields.
I would suggest a different (non Apps Script) approach. Use a Service Account and upload to that account. Either share that account's files to your own account, or copy them to your own Google Dtive.

Write to a Google spreadsheet from JavaScript using the Public API access (no OAuth)

I'd like to allow a user to visit one of my sites, enter some information into a field, and then save that information into a Google Spreadsheet via JavaScript.
I don't want the user to login via Google or have to do any special authentication.
It's Ok if the spreadsheet needs to be open to public; the data's not sensitive.
I don't want to use a Google Form, I want to have full control over the client-side UI.
I've been reading through the Google developer docs, but they only make mention to an OAuth login solution. The Google Developer Console allows you to create a "Public API access key", but does not explain how it's used.
All of the examples are for the scenario where the user is using your app to access his own files. In your case, you want the app to access your own file. This isn't easy. The only ways I can see are :-
Use a server app (appengine works well) to do the access
Very carefully set up permissions and store a refresh token in your app.
Option 2 could be your worst security nightmare if you don't do it carefully, and even then may be an infringement of Google T's and C's since it's akin to distributing your password.
Once you figure out the auth, you'll need to check out the spreadsheet API (https://developers.google.com/google-apps/spreadsheets/), as this is the API that allows you to update an existing spreadsheet. The Drive API can only upload an entire new spreadsheet.

get the e-mail address from signed-in google maps

I am trying to add a custom control (which is basically a button-link to another inner site) in a google-map for an specific list of gmail accounts. I have a django server. So, I think I can handle this if I were able to get the gmail address from the google map. Is there a way to do this without using oAuth2.0?
This is what I have in my header
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&key=AIzaSyDCzPs4j72hd2GdajAWPyQunQVlsQcqg5o"></script>
There is no way Google will allow you to access your users information without OAuth 2.0, even if they are using Google maps from your website and signed in to their Google account. Since you have the API key for (And you have not mentioned for which API it is, I am assuming it is a G+ api key for OAuth2.0). You can follow the following steps in this link to retrieve basic user info such as email id once they have signed into your website using Google account. Refer to this link to get the user info. Specifically for Google API's client Library for Python, Please follow this link.
Hope this would help!!

Accessing Google Analytics API data from javascript without authentication

I wish to access Google Analytics data through their API using Javascript.
Basically I want to display on a website a list of the most visited pages for the past week/month. I can only use javascript for this.
I found this example on the official site http://code.google.com/p/google-api-javascript-client/wiki/Samples#Google_Analytics_API
Is there any way of accessing Google Analytics data without authentication? Do I need to somehow load a username/password in? To be clear, I want a website (that has Google Analytics tracking) to load analytics data from its own account.
I thought there might be a way to make certain data public, then query that somehow... Or perhaps create a limited user to access it. I can find no examples of either.
You can't access GA withouth authentication for rather the same reason you cannot access you bank account without authentication (because that would allow everybody else to access your account without authentication which might cause some inconvenience).
Google provides a complete example for GA access via Javascript: https://developers.google.com/analytics/solutions/articles/hello-analytics-api. However I don't think that's what you want (I think for that you need to be logged in to Google to actually retrieve data).
You could however use Google Apps Script to pull data into a Google Spreadsheet and embed that into your page (at least I think that should be safe).
Updated: Google has since released the Google Analytics superProxy which allows to share Analytics data with the public safely.

Categories