0
I’m trying to use the REST components to make an HTTP request with the POST method to insert a calendar into the API, but my request is returning the error "400 - Bad Request" and before it was falling into error 401 Unauthorized I didn’t even touch the code, I can’t understand this API.
I’m trying to include the token in the request, but I don’t know if I’m doing it correctly. How can I fix it? Someone who has already integrated this API in Delphi to help me?? by favooor
My current code
procedure TOAuth2TesterFrm.incluir_btnClick(Sender: TObject);
var
json,outro_json,token: String;
begin
token:=AccessTokenEdt.Text;
json:=(
'{"kind": "calendar#calendarListEntry", "etag": "0", "id": "[email protected]", ' +
'"summary": "Calendario Outro", "description": "Descrição do evento", ' +
'{"date": "2020 August 11", "dateTime": "2020-08-11T17:35:36+03:00"}'+
'"timeZone": "Brasília-DF", "colorId": "15", "backgroundColor": "#9fc6e7", "foregroundColor": "#000000", ' +
'"selected": true, "accessRole": "owner", "primary": true, '+
'"defaultReminders": [{"method": "popup", "minutes": 30}, {"method": "email", "minutes": 10}], ' +
'"notificationSettings": {"notifications": [{"method": "email", "type": "eventCreation"}, ' +
'{"method": "email", "type": "eventChange"}, {"method": "email", "type": "eventCancellation"}, ' +
'{"method": "email", "type": "eventResponse"}]}}');
outro_json:='{"summary": "Batata"}';
try
client.ResetToDefaults;
request.ResetToDefaults;
response.ResetToDefaults;
client.BaseURL:='https://www.googleapis.com/calendar/v3/';
response.ContentType := 'application/json';
request.Method := TRESTRequestMethod.rmPOST;
request.Body.ClearBody;
request.AddBody(outro_json);
client.AcceptEncoding:='utf-8';
client.ContentType:='application/json';
request.Resource := 'calendars';
request.Params.AddHeader('Authorization','Bearer '+token);
request.Params.ParameterByName('Authorization').Options := [poDoNotEncode];
request.Execute;
ShowMessage(request.Response.StatusCode.ToString);
finally
request.Free;
response.Free;
client.Free;
end;
end;
https://developers.google.com/calendar/auth I believe I need to call the authentication API first, I just took a look at the documentation I haven’t tried to implement yet
– JMSlasher
Hello, try doing using Restrequest4delphi, it is much simpler and easy to use. It might help you... https://github.com/viniciussanchez/RESTRequest4Delphi
– Vinicius Sanchez