публичный класс GoogleContact {
приватная статическая финальная JsonFactory JSON_FACTORY = new JacksonFactory ();
static String clientId="";
static String clientSecret="";
static String token="";
public static void main(String[] arg) {
ContactsService service = new ContactsService("contacts.googleapis.com");
NetHttpTransport httpTransport=null;
try {
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
} catch (GeneralSecurityException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setClientSecrets(clientId, clientSecret)
.build().setRefreshToken(token);
try {
credential.refreshToken();
service.setOAuth2Credentials(credential);
service.useSsl();
} catch (Exception e) {
e.printStackTrace();
}
}
}
ответ:
com.google.api.client.auth.oauth2.TokenResponseException: 400 неверных запросов
{
"ошибка": "недействительный_грам",
"error_description": "Неверный запрос"
}
на com.google.api.client.auth.oauth2.TokenResponseException.from (TokenResponseException.java:105)
на com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed (TokenRequest.java:287)
на com.google.api.client.auth.oauth2.TokenRequest.execute (TokenRequest.java:307)
на com.google.api.client.auth.oauth2.Credential.executeRefreshToken (Credential.java:570)
на com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken (GoogleCredential.java:247)
на com.google.api.client.auth.oauth2.Credential.refreshToken (Credential.java:489)