Use Google Picker without logging in with Google account (with OAuth) - javascript

Is it possible to present the Google Picker to a user who isn't logged in with her Google account? I would like to let the user select files from a shared Google Drive of the Google account of my website. I can access these files with OAuth on the server. But is it also possible to present the files with Google Picker? Maybe with this method:
PickerBuilder.setOAuthToken(string)
Sets an OAuth token to use for authenticating the current user.
Depending on the scope of the token, only certain views will display
data. Valid scopes are Google Docs, Drive, and Photos. This method
should be used instead of .setAuthUser when a user is authenticated
with OAuth.
Google Picker API reference
I have tried this and I think it is not possible. Or is it?

This method of the API does work (I use it currently). Just note that the auth token from google expires and you may need to refresh your token otherwise the google picker will return a 401 when trying to retrieve the list of files from google drive.
PickerBuilder.setOAuthToken(string)

Related

Accessing google anyaltics API in my aaplication

I am currently working with the Google Analytics API. I have implemented ga react package, so the analytics tool can show me the required data.
As per my understanding, Google uses OAuth 2.0 to identify the user and grant access. As my application has it's own user(s) and every user is not available in google.
Is it possible to access the Google analytics API inside my application?. API should get called using an only the API key.
So is it possible to access Google analytics API with the only key?
First off let me start by saying im not sure i understand this statement
As my application has it's own user(s) and every user is not available in google.
I am going to assume that you are trying to show the users of your application the analytics data from a single analytics account which they dont have access to.
API Keys
Api keys are used to access public data only. Public data is data that is not owned by any user. Public Videos on YouTube, Google analytics meta data API, Holiday calendars on google calendar these are all examples of Public data not owned by any user.
Private data
In order to access private user data you must have the permission of the user who has access to that data. Google analytics data is private user data you own the data associated with your account. In order for your application to access that data it must have your permission to do so. Permission is grated using Oauth2.
If you will only ever be accessing your own account and you will not be accessing data owned by other users then you could consider using a service account. Service accounts are dummy users you can share your google analytics account with the service account there by preauthorizing its access and it will then be able to access the data without needing to be logged in all the time. The issue with service accounts is that it cant be used client side you will need to use server sided code for this. I am not a react developer so im not sure if thats one of the JavaScript frameworks that can also run server-sided or not.

getting a google analytics access token and how to use it in google sheets script

I am currently pulling data from the API query URI from the query explorer from google. https://ga-dev-tools.appspot.com/query-explorer/ It's possible here to include a 60 minute access token.
Now I want a non expiring access token and gotten as far as the API Project website from google and I have generated a client id and secret.
I tried to add the client_id and client_secret as parameters to the url like so:
url&client_id=xxx&client_secret=yyy
This does not work.
How can I generate a working access token in Google (Sheets) scripts?
Thanks
I think you need to start at the beginning.
To get an Access token you need to use a client id and client secret to request access of a user. When the user grants your application access then you will be given an access token. A good place to start Using OAuth 2.0 to Access Google APIs
Usage:
RestRequesturl?access_token=[yourtoken]
When you request access of the user you send scopes with it scopes denote what access your application will need. There is a large list of scopes for Google here in your case you will need to request the scope for Google analytics and the scope for google sheets this will allow you to access both the user google analytics account and their Google Sheets.
As you know access tokens expire after an hour for that you need a refresh token a refresh token will allow you to request a new access token of the authentication sever without having to request access for the user again. I am not a JS developer but i know you can get a refresh token with node.js but i don't think you can with pure js.
I have a tutorial series that may help you get up to speed. Google development for beginners reading the one on Oauth2 would probably help you. Google Developer console oauth2

Extract data using Google Analytics API without login gmail account

I am using Googe Analytics API. I had successfully configured google analytics api and get successful data but issue is that when I use any other email account to login and view the page, it says authentication issue.
I want to access analytics api without gmail login. I will hard code credentials to for login, but how to do it with javaScript?
How to get analytics data without login in api?
So if I am correct, you want to retrieve data from a Google specific account without having to log in or sign in that account.
You could use tokens to connect the API rather than manually log in (if that is what you are referring). Other options could be extracting the data into a virtual repository that you can use for presentation layer on the client side so you don't have to deal with credentials or security flaws on having to log in or hard code the authentication.
This should be do-able on javascript and jquery to make your data viewable.
To query GA without authenticating each time you will need obtain and store the refresh token while authenticating GA.
(not sure if we can retrieve refresh token with Js)
Once we have refresh token we can query API for access token again.

How to access Google Analytics through the JavaScript API with one OAuth token?

I'm working on a page that will be available to certain users where they can see shared Google Analytics data. I want to pull the data with JavaScript and I've succeeded in getting an OAuth token for the account with the GA data, but it expires in 1 hour.
How can I use this token for all users coming to the page? I don't need the users to be able to access their own GA data, just the shared data. Is there a way to make the token permanent or to refresh it?
Below I have listed three different possible solutions:
The easiest method might be to grant permission for your desired users to have read access to the view (profile) you want to share and use the embed API to authenticate those users and display that data.
You could look into using the Google Analytics Super proxy. The Google Analytics superProxy allows you to publicly share your Google Analytics reporting data. You can use it to power your own custom dashboards and widgets, transform responses to various formats, test, and much more.
Or you could look into using an authenticated service account. The Google OAuth 2.0 system supports server-to-server interactions such as those between a web application and a Google service. For this scenario you need a service account, which is an account that belongs to your application instead of to an individual end user. Your application calls Google APIs on behalf of the service account, so users aren't directly involved.

Google analytics credentials

I am currently new for Google analytics API throu Javascript.
I am implementing some of charts and for first load, page is redirecting me to google site to login with Analytics account and then returning to my orignal page, refresh & chart show.
Now, instead of redirecting to google analytics, is there any other way that I can store credentials on either in code behind or in config file and it will be read from there when page get loaded?
Let me know if there are any other ways/ ideas around?
I can give you some help.
Initially we need to authenticate the users, For that purpose we are redirecting the user to Google.[Mostly using Oauth]
After the authentication done. Google will redirect to your site with the access Token.
Access token is the key to fetch the analytics data from Google's database by using Management API and core reporting API.
You have to do some exchanges with google to make the token as permanent and you can store it your database.But based on some conditons this token may expire.
Visit this url : https://developers.google.com/analytics/devguides/ and understand the Google Analytics, Core Reporting API and Oauth Process
Down load this useful PHP client library for Google Analytics https://code.google.com/p/google-api-php-client/ and have fun.

Categories

Resources