Delegates & act-as
X 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.