我想知道是否可以使用Apache HttpClient调用需要身份验证的Google API,例如Google Calendar API,并且不需要Google代码或库。 (并且需要代码去做)使用Apache HttpClient调用Google auth API
这是我到目前为止的代码,它得到一个认证错误, 你对用户/密码有什么用处?
HttpPost request = new HttpPost("https://www.googleapis.com/calendar/v3/users/me/calendarList/primary?key=mykey");
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY),
new UsernamePasswordCredentials(user, password));
HttpResponse response = client.execute(request);
错误:
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
注意这是一个非用户交互过程,它需要每隔一小时检查一次日历并且没有任何过期的凭据 – James