Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello Community
I'm looking for an automatic solution to recover the token for googledrive(web service REST or function java )
I retrieve the token manually but it expires after 3500sec
thks for your help
There is no "out of the box" automatic way of doing this. I wrote a tutorial a couple of years ago showing you this can be achieved using refresh tokens. The tutorial is here (https://www.rilhia.com/tutorials/using-oauth-20-talend-access-google-apis). It may need a little tweaking (you can download the job), but it should give an idea of how to manage this.
Thanks for this excellent tutorial .
how i can download the job ?
There is a link ("here" in red) at end in the last paragraph. It was built in 5.5 I believe, so should easily upgrade to whatever version you are using (I am assuming you are using a version older than 5.5).
Thank you for rour response .
when i test your job with my drive file i have the erreur .
---------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.
| tLogRow_2 |
|=--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------=|
|errorCode|errorMessage |
|=--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------=|
|401 |{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
|
'---------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
.---------+-------------------------------.
| tLogRow_4 |
|=--------+------------------------------=|
|errorCode|errorMessage |
|=--------+------------------------------=|
|400 |{
"error" : "invalid_grant"
}|
'---------+-------------------------------'
The tokens do not exist. Revoke access using this URL https://accounts.google.com/b/0/IssuedAuthSubTokens and then run the job again
.------------+-----.
| tLogRow_5 |
|=-----------+----=|
|key |value|
|=-----------+----=|
|access_token| |
'------------+-----'
Have you downloaded the associated context variable file as well? You will need that. You can produce it yourself or download it. It will need your credentials in there. Also, there were a couple of issues raised (mentioned below in the comments) which some people had. I have described how to resolve those in the comments below as well.
yes i downloaed the context file and i repalced with my secret_id, client_id..
but when i use only refrech acces i have the erreur (in joint )
Exception in component tRESTClient_1 (TEST2)
javax.ws.rs.BadRequestException: HTTP 400 Bad Request
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.cxf.jaxrs.client.AbstractClient.convertToWebApplicationException(AbstractClient.java:507)
at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:902)
at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:426)
at org.apache.cxf.jaxrs.client.WebClient.post(WebClient.java:456)
at local_project.test2_0_1.TEST2.tRESTClient_1Process(TEST2.java:1530)
at local_project.test2_0_1.TEST2.runJobInTOS(TEST2.java:2160)
at local_project.test2_0_1.TEST2.main(TEST2.java:2009)
I have just downloaded this tutorial code onto my Mac (I wrote it on a Windows machine), cleared the contents of the context file and repopulated it with my Google Credentials (leaving both tokens blank). The first time I ran it I got an issue with Google not permitting me to run it because of a lack of a Product Name. This must be a new requirement since I wrote the tutorial. However, there was no need to edit the tutorial code, I simply went to the Google API Console and amended my credentials to be up to date (they were previously about 2 years old). I then ran it and it worked first time.
So, I can only assume that your credentials must be wrong somewhere. You cannot use the credentials you will find in the file since they are rubbish for demonstration only. Below are the values you need for your first file. After the job has been run successfully for the first time, they will be populated completely. See that my tokens are missing. Also see where I have values in curly brackets, these need to be specific to your user. If you followed my tutorial in how I configured my Google API, the redirect_uri and scope should match below.
client_secret;{YOUR SECRET} redirect_uri;http%3A%2F%2Flocalhost refresh_token; scope;https://www.googleapis.com/auth/drive context_file;{YOUR CONTEXT FILE PATH} access_token; client_id;{YOUR CLIENT ID}
If this doesn't work I am afraid I am not entirely sure what it is without looking at it myself. As I said, I downloaded the code and added it to my machine to test it and apart from playing with a few credential changes, it worked as expected.
Hello ,
thank you for your responses .
i have a erreur when i copy the URL in the web brwser
Ce site est inaccessible
localhost n'autorise pas la connexion.