Zig
Zig
Delete File
See more Google Drive Examples
Permanently deletes a file owned by the user without moving it to the trash. If the target is a folder, all descendants owned by the user are also deleted.See Google Drive Files delete for more information.
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// It requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// This example uses a previously obtained access token having permission for the
// Google Drive scope.
const g_auth = try chilkat.AuthGoogle.init();
defer g_auth.deinit();
g_auth.setAccessToken("GOOGLE-DRIVE-ACCESS-TOKEN");
const rest = try chilkat.Rest.init();
defer rest.deinit();
// Connect using TLS.
const b_auto_reconnect = true;
try rest.connect("www.googleapis.com", 443, true, b_auto_reconnect);
// Provide the authentication credentials (i.e. the access token)
rest.setAuthGoogle(g_auth) catch {};
// To delete a file, we must use the fileId.
// This must've been obtained by listing or searching for the file
// to get the metadata.
// Assume we already did that an have the fileId
const file_id = "0B53Q6OSTWYoldUprZVU1ZVQ5Z0k";
const sb_path = try chilkat.StringBuilder.init();
defer sb_path.deinit();
sb_path.append("/drive/v3/files/") catch {};
sb_path.append(file_id) catch {};
const json_response = rest.fullRequestNoBody(alloc, "DELETE", try sb_path.getAsString(alloc)) catch {
std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
return;
};
// A successful response will have a status code equal to 204 and the response body is empty.
// (If not successful, then there should be a JSON response body with information..)
if (rest.getResponseStatusCode() != 204) {
std.debug.print("response status code = {d}\n", .{rest.getResponseStatusCode()});
std.debug.print("response status text = {s}\n", .{try rest.getResponseStatusText(alloc)});
std.debug.print("response header: {s}\n", .{try rest.getResponseHeader(alloc)});
std.debug.print("response JSON: {s}\n", .{json_response});
return;
}
std.debug.print("File deleted.\n", .{});
}