Sample code for 30+ languages & platforms
Zig

Get Current User Information

See more Facebook Examples

Demonstrates how to retrieve information about the current Facebook user. This is the most basic thing to get working first (after obtaining an access token).

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // This example assumes we previously obtained an access token
    const oauth2 = try chilkat.OAuth2.init();
    defer oauth2.deinit();
    oauth2.setAccessToken("FACEBOOK-ACCESS-TOKEN");

    const rest = try chilkat.Rest.init();
    defer rest.deinit();

    // Connect to Facebook and send the following GET request:

    // GET /v2.7/me HTTP/1.1
    // Host: graph.facebook.com
    const b_auto_reconnect = true;
    rest.connect("graph.facebook.com", 443, true, b_auto_reconnect) catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    // Provide the authentication credentials (i.e. the access key)
    rest.setAuthOAuth2(oauth2) catch {};

    const response_json = rest.fullRequestNoBody(alloc, "GET", "/v2.7/me") catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("{s}\n", .{response_json});

    // The responseJson looks like this:
    // {"name":"John Doe","id":"10111011320111110"}
}