Java 如何解决google contact api中的{“错误”:“无效”授权、“错误描述”:“错误请求”问题
公共类谷歌联系人{ 私有静态最终JsonFactory JSON_FACTORY=new JacksonFactory() } 答复是: com.google.api.client.auth.oauth2.TokenResponseException:400错误请求 { “错误”:“无效的授权”, “错误描述”:“错误请求” } 位于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)Java 如何解决google contact api中的{“错误”:“无效”授权、“错误描述”:“错误请求”问题,java,google-api,Java,Google Api,公共类谷歌联系人{ 私有静态最终JsonFactory JSON_FACTORY=new JacksonFactory() } 答复是: com.google.api.client.auth.oauth2.TokenResponseException:400错误请求 { “错误”:“无效的授权”, “错误描述”:“错误请求” } 位于com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseExcepti
在com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)上,我遇到了相同的异常。然后我生成了一个新的credentials.json文件,并从tokens文件夹中删除了旧的令牌。然后我运行这个程序,它工作了,并生成了一个新的令牌
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();
}
}