473,699 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

(JAVA) Google API - unable to obtain new “access token” using “refresh token

1 New Member
I want to obtain a new "access token" based on the "refresh token" saved in database for Google API Analytics.

Here is the code I wrote:

Expand|Select|Wrap|Line Numbers
  1. GoogleCredential.Builder credentialBuilder = new GoogleCredential.Builder()
  2.         .setTransport(HTTP_TRANSPORT).setJsonFactory(JSON_FACTORY)
  3.         .setClientSecrets(CLIENT_ID, CLIENT_SECRET);
  4. credentialBuilder.addRefreshListener(new MyCredentialRefreshListener());
  6. credential = credentialBuilder.build();
  7. credential.setRefreshToken("saved_refresh_token_from_database");
  9. try {
  10.     credential.refreshToken();
  11. } catch (IOException e) {
  12.     e.printStackTrace();
  13. }
  16. class MyCredentialRefreshListener implements CredentialRefreshListener {
  17.     public void onTokenResponse(Credential cr, TokenResponse tr) {
  18.        System.out.println("Credential was refreshed successfully.");
  19.     }
  21.     public void onTokenErrorResponse(Credential cr, TokenErrorResponse tr) {
  22.         System.out.println(tr);
  23.     }
  24.  }
I get this message:

Expand|Select|Wrap|Line Numbers
  1. com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad
  3. Request { "error" : "invalid_grant" }
I use the same CLIENT_ID, CLIENT_SECRET and "refresh token" in a php script and there I managed to get the new "access token" using "refresh token" when "access token" expired.

I wrote the code based on javadoc.google-oauth-java-client.

Any person here knows how to modify the code to obtain the new access token ?

Thanks in advance.
Nov 12 '12 #1
0 3121

Sign in to post your reply or Sign up for a free account.

Similar topics

by: SBK | last post by:
I'm having a problem: I connect to an MS access db using jet oledb (it has a password). If the db doesn't have a password, everything works fine. If i do, access gets locked down (.ldb) with the access db 'Admin' user. Closing the Windows Form that uses the oledbconnection has no effect on the ldb (even though i close the connection etc). I can't delete the ldb manually or programatically (after the .net appication is closed - the ldb...
by: soup_or_power | last post by:
The pop up window has several checkboxes. I'm unable to access the checkboxes using the handle from window.open. Any way to do this? var display; function showSugg(but_id, sugg1, sugg2, sugg3, sugg4, sugg5) { display=window.open('','_blank','menubar=0,location=no,status=no,directories=no,toolbar=no,scrollbars=yes,height=150,width=190')
by: SaCompGeek | last post by:
I have a class that defines a Key/Name value collection that i generated by and XML Element with multiple attributes. The attribute are used to create the collection of 'Binate' objects. This is writte in VB.NET 1.1. I have this class in a Win32 test application and it works fine. Whe I put the class in a Web app I get the following error. The assembl it is in is not directory in the ASP.NET application but in one tha the ASP.NET...
by: Erik H. | last post by:
I have an ASPX page in which I am trying to bind a datagrid to a dataset pulled from Microsoft Access DB using code inline method. For some reason, the compiler is having a problem with 'using'. Any help here would be much appreciated. Thanks! Getting the following error: CS1519: Invalid token 'using' in class, struct, or interface member declaration My Code:
by: Erik H. | last post by:
I have an ASPX page in which I am trying to bind a datagrid to a dataset pulled from Microsoft Access DB using code inline method. For some reason, the compiler is having a problem with 'using'. Any help here would be much appreciated. Thanks! Getting the following error: Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify...
by: Vikram | last post by:
I have added some input elements on a page using javascript at client side. when i submit the page, i am unable to access the values of input elements created using request.form. Are elements created using javascript are available at the server? if not how can i do the above thing so that there values can be accessed. I dont want to postback page everytime i need to create a new element.
by: Mazharrana | last post by:
hi I want to access registry using java, I want to find list of hardware or software installed in my PC using java programe. How can i do this? If any one know ? Please help me. Regards Mazhar
by: Ben Walling | last post by:
I'm getting the following error on one of 110 machines that is using a webservice to upload database changes to a central location: System.Web.Services Server was unable to read request. --There is an error in XML document (3, 2148906). --This is an unexpected token. The expected token is 'NAME'. Line 3, position 2148909. at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse...
by: ADezii | last post by:
In Tip #12, we showed how to display a Progress Meter within Access by using the SysCmd() Function. By using this same Function, with different Action Arguments, we will now demonstrate how you can return specific Access information as well as determining an Object's (Table, Form, Report, Macro, Module, etc) State. Instead of preceding the code display with an Overview, I decided to more fully comment the code, since for the most part it will be...
by: =?Utf-8?B?Y2FzaGRlc2ttYWM=?= | last post by:
Hi, has anyone come across this error before: This is an unexpected token. The expected token is 'NAME' I am getting it when trying to send an xml file across a web service layer. The xml file is well formed, having been checked with XmlSpy. The size of the file is roughly 119KB. I think it was written in MS Word and the HTML is
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.