File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed
Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,8 @@ This is a comprehensive guide of all methods available for the Twitter API v2 on
6262 - [ Mute someone] ( #mute-someone )
6363 - [ Unmute someone] ( #unmute-someone )
6464 - [ Get users that are muted by you] ( #get-users-that-are-muted-by-you )
65+ - [ Usage] ( #usage )
66+ - [ Get usage] ( #get-usage )
6567 - [ Lists] ( #lists )
6668 - [ Single list by id] ( #single-list-by-id )
6769 - [ Owned lists] ( #owned-lists )
@@ -997,6 +999,24 @@ for await (const mutedUser of mutedPaginator) {
997999}
9981000```
9991001
1002+ ### Get usage
1003+
1004+ ** Method** : ` .usage() `
1005+
1006+ ** Endpoint** : ` usage/tweets `
1007+
1008+ ** Right level** : ` Read-only `
1009+
1010+ ** Arguments** :
1011+ - ` options: TweetUsageV2Params `
1012+
1013+ ** Returns** : ` TweetV2UsageResult `
1014+
1015+ ** Example**
1016+ ``` ts
1017+ const usage = await client .v2 .usage ({ ' usage.fields' : [' daily_project_usage' ] });
1018+ ```
1019+
10001020## Lists
10011021
10021022### Single list by id
Original file line number Diff line number Diff line change @@ -186,3 +186,32 @@ export interface BatchComplianceV2JobResult {
186186export type BatchComplianceListV2Result = DataV2 < BatchComplianceJobV2 [ ] > ;
187187
188188export type BatchComplianceV2Result = DataV2 < BatchComplianceJobV2 > ;
189+
190+ /// -- Usage --
191+
192+ type TUsageField = 'cap_reset_day' | 'daily_client_app_usage' | 'daily_project_usage' | 'project_cap' | 'project_id' | 'project_usage' ;
193+
194+ export type TweetUsageV2Params = {
195+ days ?: number ;
196+ 'usage.fields' ?: TUsageField [ ] ;
197+ }
198+
199+ type TUsageDaily = {
200+ /** ISO date string */
201+ date : string ;
202+ usage : string ;
203+ } ;
204+
205+ export type TweetV2UsageResult = DataV2 < {
206+ project_id ?: string ;
207+ project_cap ?: string ;
208+ project_usage ?: string ;
209+ cap_reset_day ?: number ;
210+ daily_project_usage ?: {
211+ project_id : string ;
212+ usage : TUsageDaily [ ] ;
213+ } [ ] ;
214+ daily_client_app_usage ?: {
215+ usage : TUsageDaily [ ] ;
216+ } [ ] ;
217+ } > ;
Original file line number Diff line number Diff line change @@ -54,6 +54,8 @@ import {
5454 TweetV2PaginableTimelineResult ,
5555 TweetV2HomeTimelineParams ,
5656 TweetV2HomeTimelineResult ,
57+ TweetUsageV2Params ,
58+ TweetV2UsageResult ,
5759} from '../types' ;
5860import {
5961 TweetSearchAllV2Paginator ,
@@ -862,4 +864,15 @@ export default class TwitterApiv2ReadOnly extends TwitterApiSubClient {
862864 . filter ( line => line )
863865 . map ( line => JSON . parse ( line ) ) as BatchComplianceV2JobResult [ ] ;
864866 }
867+
868+ /* Usage */
869+
870+ /**
871+ * Allows you to retrieve your project usage.
872+ *
873+ * https://developer.x.com/en/docs/x-api/usage/tweets/introduction
874+ */
875+ public async usage ( options : Partial < TweetUsageV2Params > = { } ) {
876+ return this . get < TweetV2UsageResult > ( 'usage/tweets' , options ) ;
877+ }
865878}
You can’t perform that action at this time.
0 commit comments