Перейдите к URL и дает согласие:Google API v3: Добавить событие в Google Calendar
https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/calendar&state=%2Fprofile&redirect_uri=http://localhost:8080/webapp_name/calendar/calendar.html?operation=oauth2callback&response_type=code&client_id=84294424369.apps.googleusercontent.com&approval_prompt=force
я получаю 'код' в мой метод, который будет использоваться, чтобы получить маркер доступа, как
HttpClient client = new HttpClient();
String accessTokenURL = "https://accounts.google.com/o/oauth2/token";
PostMethod method = new PostMethod(accessTokenURL);
method.addParameter("code",request.getParameter("code")); method.addParameter("client_id","84294424369.apps.googleusercontent.com");
method.addParameter("client_secret","sPXaCrOX_19df5iXjII7ZlCp"); method.addParameter("redirect_uri",request.getRequestURL()+"?operation=oauth2callback");
method.addParameter("grant_type","authorization_code");
int returnCode = client.executeMethod(method);
HashMap gctoken = (HashMap)new JSONDeserializer().deserialize(method.getResponseBodyAsString());
String accessToken = gctoken.get("access_token").toString();
Теперь, используя указанную выше маркер, чтобы вставить событие в моем календаре:
String accessTokenURL = "https://www.googleapis.com/calendar/v3/calendars/[email protected]om/events";
PostMethod method = new PostMethod(accessTokenURL);
method.addParameter("access_token",accessToken);
method.addParameter("summary","New york trip");
method.addParameter("description","Chicago desc");
method.addParameter("start",(new Date()).toString());
Calendar cal = new GregorianCalendar();
cal.setTime(new Date());
cal.add(Calendar.HOUR,1);
method.addParameter("end",cal.getTime().toString());
int returnCode = client.executeMethod(method);
System.out.println("Event created-------> "+method.getResponseBodyAsString());
Приведенный выше код для вставки дает мне ошибку
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
HOW to solve this Credentials problem and create entry in my google calendar?
Какой язык этот код? Взгляните на это сообщение в блоге: http://bittwiddlers.org/?p=212#awp::?p=212 – HK1