Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

REST CONNECTOR locate the Authorization token

I am trying to connect to google analytics by following this guide http://help.qlik.com/Connectors/en-US/connectors/#../Subsystems/REST_connector_help/Content/1.0/Crea...

But I get stuck on step 7. Open Developer tools in Google Chrome and locate the Authorization token

How do i locate the token?

Labels (1)
62 Replies
john9inno
Creator
Creator

I really have to say thanks to Karl and Bjorn,

I could achieve multiple things from this posting.

GA data by campaign, Device, Screen Resolution, location, date, Source and etc.

Scheduling wasn't too difficult, if you are familiar with QMC.

As GA provides 50K API call per day, even I could do ETL at every 30 seconds to show how web performs on the day with sales figure included.. (only from 8AM to 8PM).

there are few things that you need to aware when you use GA real time data of the day. that may differ from historical data table. (showed me 2~3% error)

if there are huge number of campaigns occur every week, you may need to talk to Marketing campaign manager to make that ETL is possible as there is limitation.

thanks again Karl and Bjorn.

John

anderseriksson
Partner - Specialist
Partner - Specialist

Vacation got in the way of this.

You could create the connection BUT which connection was that?

Fetching data from GA or refreshing the Access token?

I could create the connection to GA using a token and fetch some data but the Access token timed out after a short while.

My question is how to automate the refresh of the Access token used when connecting to GA?

john9inno
Creator
Creator

This will give you clues.

https://developer.chrome.com/extensions/tut_oauth

also, Bjorn explained well in one of his reply as shown below.

Hi Karl,

Sorry about the delay in responding. I've been playing around a bit with this in Qlik Sense as well, and I managed to alter the parameters for the connection using WITH CONNECTION, in a similar way as above. This worked even in Legacy mode (which was a surprise to me).

There is one big hurdle though and that is when creating Data connections; the connection must be successful or you cannot save the settings. Even when pressing "Save" the connection is checked and if it fails settings won't be saved.

When working with APIs you cannot hardcode parameters in the URL when setting up the connection, basically because not all parameters may be known at this stage.

To get around this I simply created two connections using the REST Connector, one for GET (LIB: Google Analytics API) and one for POST (LIB: Google Authorization) and used an open JSON server at jsonplaceholder.typicode.com wheen creating the connections (you cannot alter the Method GET/POST using WITH CONNECTION). I then followed the same process as above, and used WITH CONNECTION to alter the LIB settings and pointed the URL to the entry-points for Google APIs. Here's a small example script for Sense:

  1. IF vTokenExpires <= now() THEN 
  2.   LET vRequestBody =''; 
  3.   LET vRequestBody = vRequestBody & 'grant_type=refresh_token'; 
  4.   LET vRequestBody = vRequestBody & '&client_id=' & '$(vClient_id)'; 
  5.   LET vRequestBody = vRequestBody & '&client_secret=' & '$(vClient_secret)'; 
  6.   LET vRequestBody = vRequestBody & '&refresh_token=' & '$(vRefresh_token)'; 
  7.  
  8.   LIB CONNECT TO 'Google Authorization'; 
  9.  
  10.   access_token: 
  11.   SQL SELECT 
  12.   "access_token", 
  13.   "token_type", 
  14.   "expires_in" 
  15.   FROM JSON (wrap on) "root" 
  16.     WITH CONNECTION ( 
  17.     URL "https://www.googleapis.com/oauth2/v4/token", 
  18.     HTTPHEADER "Content-Type" "application/x-www-form-urlencoded", 
  19.   BODY "$(vRequestBody)" 
  20.   ); 
  21.   LET vExpiresIn = peek('expires_in',0,'access_token'); 
  22.   LET vAccessToken = peek('access_token',0,'access_token'); 
  23.   LET vTokenExpires = timestamp(now() + $(vExpiresIn)/86400); 
  24.  
  25.  
  26.  
  27.  
  28. ENDIF   

Next step would be to dynamically render the URL to query Google Analytics, using variables. Not done here yet, so will get back to you with that part.

Not applicable
Author

Hi John,

Its quite obvious you have a great knowledge of scripting, I will try your above method and try to connect to GA and lets see how data comes , Yes it was most critical part to settle a connection which don't need to create auth key , I will follow your above script and lets see how data comes , will inform you

john9inno
Creator
Creator

Thanks.

QV source is great application.

there is no doubt. Only down side is you don't experience every step of API connection which is very interesting to be honest.

not only my knowledge of scripting is good but also very importantly Karl and Bjorn explained A to Z "every thing" in this post you need follow.

So, read from the top to bottom. I read 10+ times

Thanks,

John

Anonymous
Not applicable
Author

Hi bmw,

I start a discussion How i generate file from rest connector (from Flurry) every days , and i still have some problems to run this script.

I use QlikSense, and the processe that i use to create Rest Connection in this case with Flurry is:

Create New Connection:

To do this define the

- URL: http://api.flurry.com/eventMetrics/Event‌?

- Time Out: 30

- Method: GET

....

Query Parameters:

- apiAccessCode: XXXXXXXXX

- apiKey: XXXXXXXX

- startDate: 2016-08-01

- endDate: 2016-08-02

- eventName: APP-View

My problem is, i need to create a script where i can change the start an end date to a variable to import and save in qvd's day by day from flurry automatically. (The script run every day's and create a file qvd with last day data and/or diferente event name).

But inside this Edit Connection (REST) i can't use variables and it's mandatory define this query's parameters.

Your script code make sense but i can't apply in my case.

Can you help me please?

Thanks in advance.

Regards,

Pedro Lopes

Bjorn_Wedbratt
Former Employee
Former Employee

Hi Pedro,

I have no specific knowledge around flurry or yahoo's api, but it looks like you simply need to send a GET request using something like:


http://api.flurry.com/eventMetrics/Event?apiAccessCode=APIACCESSCODE&apiKey=APIKEY&startDate=STARTDATE&endDate=ENDDATE&eventName=EVENTNAME&versionName=VERSIONNAME

If that's the case simply use the WITH CONNECTION statement as described in the documentation at Select REST data with the Data load editor ‒ Qlik Connectors

LET vStartDate = 'STARTDATE';

LET vEndDate = 'ENDDATE';

Let vURL = 'http://api.flurry.com/eventMetrics/Event?';

LET vURL = vURL & 'apiAccessCode=APIACCESSCODE&apiKey=APIKEY';

LET vURL = vURL & '&startDate=' &  '$(vStartDate)';

LET vURL = vURL & '&endDate=' & '$(vEndDate)';

LET vURL = vURL & '&eventName=EVENTNAME&versionName=VERSIONNAME';

SQL SELECT

<code>

FROM JSON

WITH CONNECTION (

URL "$(vURL)"

);

You cannot use variables in the connect dialog (unfortunately) so you first need to either create a connect statement with static start/end dates and then alter it as above, or you need to define a connection using "dummy" values and then alter it in the script, if you cannot make a successful connection to the source you're after (when creating a connection, it must be successful or it won't be created).

This is what I did when trying to connect to Google Analytics, where I needed a connection to be able to POST to the token API, but I couldn't fill out all the values when creating the connection for various reasons. Instead I created a connection to jsonplaceholder.typicode.com using POST method. Once the connection was in place I could alter it using WITH CONNECTION and change the URL, attach http headers and dynamically craft the request body required.

Anonymous
Not applicable
Author

Hi Björn,

Thanks for your help.

The script is work.

Thanks in advance,

Pedro Lopes

Not applicable
Author

Thanks bmw and  Karl for this post.
It provided a lot of insights.

Now I have got data from Google Analytics into some tables (though the structure is bit wierd).
Now, I need to restructure this data and I am facing problem with it.
I have asked question in another thread, see if you can help me there?How to make new table with fields name coming from rows of an existing table?

berryandcherry6
Creator II
Creator II

Hi All,

I  need to fetch Google Analytics data in Qliksense 3.0. For this

1.)i have got client_id, Client_secret & Refresh_token from https://developers.google.com/oauthplayground.

2.)And copy pasted below code from this link REST CONNECTOR  locate the Authorization token .  and Started to create connection "Google Authorization".

For second point to work, i need to create connection "Google Authorization". I am stuck here, if i create connection by Create new connection --> Qlik Rest Connector -->  URL = https://www.googleapis.com/oauth2/v4/token. It shows Remote Server returned an error:(404)Not found.


Can Anyone explain how i could create connection manually for "Google Authorization".