Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Using OAuth 2.0 with Talend to Access Google APIs

This tutorial was originally written in 2014 for my website. Although the Google screenshots may be slightly out of date and I wrote this using version 5.5.1 of Talend, you should still be able to make use of this. I have attached a copy of the job and a copy of the parameters file I used for this.

 

Google make use of the OAuth 2.0 protocol for authentication for (I think, but am happy to be corrected) all of their services. They do a pretty good job of describing the protocol. Once you have read through the documentation you should have a better idea of what you are doing, which should make this easier. The Google documentation is here.

 

The first thing that needs to be done is to create a Google Project. This is described below....

 

Create a Google Project

 



To see the whole post, download it here
Labels (5)
30 Replies
Anonymous
Not applicable
Author

...Continued

15) "Get Access Token and Refresh Token" (tRESTClient)

This component is used to retrieve an access token and refresh token using the authorisation code retrieved from the component before. 

To configure this component copy the configuration shown below. Ensure that the sections circled in red are set correctly. To add the "Query parameters" use the green plus symbol circled in red.

0683p000009Lzvf.png

The values required can be seen above, but you can find them below so that you can copy and paste them.....

 

URL: ""<



To see the whole post, download it here
OriginalPost.pdf
somersst
Contributor III
Contributor III

Hi,

 

I followed the different steps, but I receive the following message : 

https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/drive&state=12345678...
s://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/drive
400|{
"error": "invalid_grant",
"error_description": "Malformed auth code."
}

 

Any idea on what I can be doing wrong??

Anonymous
Not applicable
Author

I can see that your redirect_uri is incorrect. I used "http://localhost" (or "http%3A%2F%2Flocalhost" with the address url encoded)

 

https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/drive&state=123456789qwertyui&redirect_uri=https://developers.google.com/oauthplayground&response_type=code&client_id=XXXX-t701hme370kfagcvo1052id7e8jblo8b.apps.googleusercontent.com&approval_prompt=auto&include_granted_scopes=true&access_type=offline
somersst
Contributor III
Contributor III

Hi,

 

I've corrected this.

I now have the following url :

https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/drive&state=12345678...

 

When I do this and put the correct access-token it works.

 

But unfortunateley after an hour this doesn't work anymore. I've also included the refresh token, but this doesn't seem to work.

I presume this is something that needs to be set up on the google account??

Anonymous
Not applicable
Author

It has been a while since I wrote this job (I believe I did it in 2014), so the flow may have changed slightly. But the point of this job is that once the first token is received (access token), the refresh token is saved into a CSV file. The next time the job fails and requires a new access token, the refresh token will automatically be used to create one.

 

Using the refresh token to retrieve a new access token has a slightly different flow from the original flow to generate both a refresh token and access token. This may be what is tripping you up. However, if you have received a refresh token with your first access token, you should be able to use it to  generate a new access token. 

 

Have you tried downloading the job?

somersst
Contributor III
Contributor III

I was using the job. Probably I have forgotten this step.
Schermafbeelding 2019-02-19 om 11.54.49.png
Anonymous
Not applicable
Author

Not able to view/download the image

powerchip
Contributor
Contributor

Hi,

Just tried your scenario it's great and well documented

 

I made some changes to retrieve the code

 

in the context file

replace : redirect_uri;http%3A%2F%2Flocalhost
with : redirect_uri;urn:ietf:wg:oauth:2.0:oob

 

 

In the steps
13.

replace : redirect URL
with : code

14.
comment/remove the substring part
15.
in query parameters

replace : http://localhost
with : context.redirect_uri

 

 

Result :
In the browser you can directly copy-paste the code
It's less disturbing than the error page

 

Now I need to figure out how to retrieve data from Google with TOS and use it

Anonymous
Not applicable
Author

Nice additions. This was written a long time ago and things have moved on a bit with Google OAuth 2.0 functionality. I'm glad this still works and that you have been able to improve upon it @powerchip