Communication with the Google Calendar API using REST

1

I'm using Scribe to authenticate with API of Google Calendar . Authentication with Google is done successfully returning accessToken with no problems. When I try to add a CalendarList , through the following code:

OAuthRequest request = new OAuthRequest(Verb.POST, "https://www.googleapis.com/calendar/v3/users/me/calendarList");
        JSONObject message = new JSONObject();
        message.put("id", "Teste 1");
        request.addPayload(message.toJSONString());
        service.signRequest(accessToken, request);
        Response response = request.send();

Google returns the following error this api does not support parsing form-encoded input

How should I build the request in JSON so that it has a response from Google?

    
asked by anonymous 05.12.2014 / 23:46

1 answer

2
public void createNewCalendarList(OAuthService service){
        Token newAccessToken = new Token( API_USER_TOKEN, API_USER_SECRET);
        OAuthRequest request = new OAuthRequest(Verb.POST, "https://www.googleapis.com/calendar/v3/calendars");
        JSONObject payload = new JSONObject();
        request.addHeader("Content-Type", "application/json ; charset=UTF-8");
        payload.put("summary", "Meeto");
        request.addPayload(payload.toJSONString());
        service.signRequest(newAccessToken, request);
        Response response = request.send();
        System.out.println("Reposta dos tipos da google: " + response.getBody());
    }

I had to add a Content-type, and a payload with all the necessary arguments. I used examples from the following link: link

    
07.12.2014 / 02:36