The API interface provided to custom subtask handlers for interacting with the Twitter authentication flow. This interface allows handlers to send flow requests and access the current flow token.

The API is passed to each subtask handler and provides methods necessary for implementing custom authentication subtasks. It abstracts away the low-level details of communicating with Twitter's authentication API.

import { Scraper, FlowSubtaskHandler } from "@the-convocation/twitter-scraper";

// A custom subtask handler that implements a hypothetical example subtask
const exampleHandler: FlowSubtaskHandler = async (subtaskId, response, credentials, api) => {
// Process the example subtask somehow
const data = await processExampleTask();

// Submit the processed data using the provided API
return await api.sendFlowRequest({
flow_token: api.getFlowToken(),
subtask_inputs: [{
subtask_id: subtaskId,
example_data: {
value: data,
link: "next_link"
}
}]
});
};

const scraper = new Scraper();
scraper.registerAuthSubtaskHandler("ExampleSubtask", exampleHandler);
interface FlowSubtaskHandlerApi {
    getFlowToken: () => string;
    sendFlowRequest: (
        request: TwitterUserAuthFlowRequest,
    ) => Promise<FlowTokenResult>;
}

Properties

getFlowToken: () => string

Gets the current flow token.

Type declaration

    • (): string
    • Returns string

      The current flow token

sendFlowRequest: (
    request: TwitterUserAuthFlowRequest,
) => Promise<FlowTokenResult>

Send a flow request to the Twitter API.

Type declaration