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" }]Groups
delegates.groups(opts?)
Gets the groups you belong to, with your own account first as "Owner". Pass status: "Pending" for invitations you have not answered.
delegates.group(groupId)
Gets one group with its members.
delegates.delegateAccounts(opts?)
Gets the groups the account switcher shows.
delegates.members()
Gets the accounts that can act as you.
delegates.addMember(groupId, userId, role?)
Invites a user to a group you manage as "Admin" or "Contributor".
delegates.removeMember(membershipId) / delegates.cancelInvite(membershipId)
Removes a member or cancels a pending invite.
delegates.changeRole(userId, role)
Changes a member's role.
delegates.accept(membershipId) / delegates.reject(membershipId)
Answers an invitation.
delegates.leaveGroup(membershipId)
Leaves a group.
delegates.setInvitePolicy(allowFrom)
Sets who can invite you as a delegate, "Everyone" or "OnlyFollowing".