Delegates & act-as
Twitter lets accounts grant each other delegate access. emusks exposes the delegate lists and lets any request act on behalf of an account you're a delegate for.
Listing delegates
delegates.contributees(opts?)
The accounts you can act as (accounts that have added you as a delegate). Uses the v1.1 users/contributees endpoint.
| Option | Type | Description |
|---|---|---|
opts.userId | string | Look up another user's list |
opts.screenName | string | Look up by @handle |
const accounts = await client.delegates.contributees();
// [{ id, id_str, screen_name, name, ... }]delegates.contributors(opts?)
The accounts that can act as you (delegates you've granted access to). Uses the v1.1 users/contributors endpoint.
const delegates = await client.delegates.contributors();Acting as another account
When you're a delegate for an account, set actingAs to its user id and every subsequent request carries the x-act-as-user-id header, so reads and writes happen on that account.
client.setActingAs(userId)
Set (or clear, with null) the account to act as. Returns the client for chaining.
client.setActingAs("1340268334785376258");
await client.tweets.create("posted on behalf of the delegated account");
client.setActingAs(null); // back to your own accountdelegates.actAs(userId) / delegates.stop() / delegates.current()
Convenience wrappers: actAs is an alias for setActingAs, stop clears it, and current returns the active id.
client.delegates.actAs(targetUserId);
const home = await client.timelines.home(); // the delegated account's timeline
client.delegates.stop();TIP
You can also act-as for a single call by passing the header directly to any request: client.graphql("...", { headers: { "x-act-as-user-id": userId } }). The header threads through the GraphQL, v1.1, and v2 layers.
WARNING
Acting as an account you are not a delegate for returns a Contributor access is not permitted error. Some endpoints disallow acting-as entirely.
delegates.accounts()
The accounts you can act as, read from Twitter's delegation groups (the same data x.com's account switcher and Settings, Delegate page use). Prefer this over contributees(): Twitter no longer fills the legacy users/contributees.json list, so it returns [] even when other accounts have added you.
const accounts = await client.delegates.accounts();
// [{ id, screenName, name, avatar, role: "Admin" | "Contributor" }]delegates.groups(opts?)
Every delegation group you belong to, including your own account with role: "Owner". Uses the Relay query useRelayDelegateDataQuery. Pass { status: "Pending" } for invitations you haven't answered, which come back as [{ groupId }] because Twitter only returns their ids.
delegates.members()
The accounts that can act as you, from your own delegation group (x.com, Settings, Delegate, Members). Uses the Relay query MembersDelegateQuery. Prefer it over contributors(), which Twitter no longer fills.
const members = await client.delegates.members();
// [{ id, screenName, name, avatar, role: "Admin" | "Contributor", status: "Accepted" | "Pending" }]