我正在使用以下代码来验证 google id 令牌。它总是给我以下错误。但是使用相同的标题,我可以在 POST MAN 工具中进行验证。请帮我解决这个问题。
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service =
client.resource("https://www.googleapis.com/oauth2/v3/userinfo");
try {
ClientResponse response = service.header("Authorization",
"Bearer ya29.Glt6BGkbIzLEjeeQ5Q8O51Jh7-PFD3hVLM7PORixSTVFY-
iduKE8HmK8KMtzYz-
yJ9rUqo_xY9yVKl5b6CAiTNAtFErb0bZJB3vX6vPZVRPwbY6kVCIDbukDc9FA")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Accept",
"Accept=text/html,application/xhtml+xml,
application/xml;q=0.9,*/*;q=0.8").get(ClientResponse.class);
} catch (Exception e) {
e.printStackTrace();
}
错误:
线程“主”com.sun.jersey.api.client.UniformInterfaceException 中的异常:GET https://www.googleapis.com/oauth2/v3/userinfo返回响应状态为 401 Unauthorized