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:Ā 
cjiawei
Contributor II
Contributor II

Connecting tRest / tRestClient with Google API to get access token

Hello, I am new on Talend šŸ™‚ Can I check if it is possible to use Talend to get the access key from google (https://www.googleapis.com/oauth2/v4/token) so that I am able to call this API?

 

Api URL : https://admin.googleapis.com/admin/directory/v1/users/

 

I have already managed to get the output on Postman but am not able to get the access token on Talend.

Kindly appreciate any help on this.

 

Thanks!

Labels (3)
1 Solution

Accepted Solutions
cjiawei
Contributor II
Contributor II
Author

Thanks for the reply to this post.

 

Have referred to the link you have provided but did some minor changes.

 

Instead of tRestClient have managed to get the access_token with tRest instead.

 

HTTP Header: name = "content-type" and value = "application/x-www-form-urlencoded"

 

HTTP Body : "code=xxx&client_id=xxx&client_secret=xxx&refresh_token=<>&redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&grant_type=authorization_code"

 

Greatly appreciate your help.

View solution in original post

8 Replies
Anonymous
Not applicable

OAuth2 can be tricky when you start working with it. I have put together a tutorial on this with Google quite a while ago. It may be slightly out of date, but the flow should work for you with a few a tweak. You can find this here...

https://community.qlik.com/t5/Design-and-Development/Using-OAuth-2-0-with-Talend-to-Access-Google-AP...

I have also put together a YouTube demo of this with Twitter. It is very similar and should give you a good idea of how to achieve this. You can find this here. It also comes with a demo job.

 

https://www.youtube.com/watch?v=6Irs-SvviNc&t=376s

cjiawei
Contributor II
Contributor II
Author

Appreciate the prompt reply on this.

 

Having to look through both of the materials provided, can I kindly check on the purpose of having the "code" used in the TRestClient?

I have tried to call different APIs and it doesn't seem to require so many components. ( Usually either a tRESTClient or a tRest is sufficient)

Anonymous
Not applicable

Ah, OK. These examples are to show how you can fully implement solutions to deal with creating your OAuth 2 access token AND to regenerate them from refresh tokens when they expire. They were built to automate this generation and regeneration process. When I first started using OAuth 2.0 with Google applications, I found that it was somewhat painful to go through the steps manually when token expired. This is why these jobs are somewhat bigger than you might expect.

cjiawei
Contributor II
Contributor II
Author

Ohh I see. But can I check why I am getting an Unauthorized message when I attempted to use the code to get the access and refresh token? Is there any specific permission that I would require to provide in the Google API Service?

 

0695b00000bHTrzAAG.png 

Note that the appropriate scopes should already have been authorized as I managed to access the desired output on Postman. Not really sure what other permission I might have missed out on.

Anonymous
Not applicable

OK, this is coming from Google. So it suggests that what is being sent is incorrect. Can you show me how your tRestClient is configured (basic and advanced tab) and also show me how you are generating your token? Are you able to register a token? Has the token every worked? Or does it work and then start to fail? The tokens are time limited. We will get through this, but there are lots of little bits that can catch you out.

 

Oh, don't share your tokens as they are. Make sure you either change the tokens with a few extra characters or hide them šŸ˜‰

cjiawei
Contributor II
Contributor II
Author

Thanks for the reply to this post.

 

Have referred to the link you have provided but did some minor changes.

 

Instead of tRestClient have managed to get the access_token with tRest instead.

 

HTTP Header: name = "content-type" and value = "application/x-www-form-urlencoded"

 

HTTP Body : "code=xxx&client_id=xxx&client_secret=xxx&refresh_token=<>&redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&grant_type=authorization_code"

 

Greatly appreciate your help.

Anonymous
Not applicable

I'm glad you got it working. Thanks for sharing your way alternative way of doing this. There is seldom a single "right way" of doing something and sharing different ways helps everyone. This follow-up is much appreciated šŸ‘

bwenzel
Partner - Contributor II
Partner - Contributor II

what goes in the redirect url?

 

thanks,

bob