Zig
Zig
ETrade Revoke Access Token
See more ETrade Examples
Revokes an ETrade OAuth access token.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
http.setOAuth1(true);
http.setOAuthVerifier("");
http.setOAuthConsumerKey("ETRADE_CONSUMER_KEY");
http.setOAuthConsumerSecret("ETRADE_CONSUMER_SECRET");
// Load the access token previously obtained via the OAuth1 Authorization
// This is the token that will be revoked.
const json_token = try chilkat.JsonObject.init();
defer json_token.deinit();
json_token.loadFile("qa_data/tokens/etrade.json") catch {
std.debug.print("Failed to load OAuth1 token\n", .{});
return;
};
http.setOAuthToken(try json_token.stringOf(alloc, "oauth_token"));
http.setOAuthTokenSecret(try json_token.stringOf(alloc, "oauth_token_secret"));
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpNoBody("GET", "https://api.etrade.com/oauth/revoke_access_token", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
// Make sure a successful response was received.
if (resp.getStatusCode() != 200) {
std.debug.print("{s}\n", .{try resp.getStatusLine(alloc)});
std.debug.print("{s}\n", .{try resp.getHeader(alloc)});
std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});
return;
}
// If successful, the resp.BodyStr contains something like this: Revoked Access Token
std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});
std.debug.print("Success.\n", .{});
}