@@ -46,11 +46,8 @@ export class SocialDataClient {
4646 private async makeRequest ( endpoint : string , params : Record < string , any > = { } ) : Promise < any > {
4747 const url = new URL ( `${ this . baseUrl } ${ endpoint } ` ) ;
4848
49- // Add API key to params
50- const requestParams = { ...params , api_key : this . apiKey } ;
51-
52- // Add params to URL
53- Object . entries ( requestParams ) . forEach ( ( [ key , value ] ) => {
49+ // Add params to URL (don't include API key in params)
50+ Object . entries ( params ) . forEach ( ( [ key , value ] ) => {
5451 if ( value !== undefined && value !== null ) {
5552 url . searchParams . append ( key , String ( value ) ) ;
5653 }
@@ -59,6 +56,7 @@ export class SocialDataClient {
5956 const response = await fetch ( url . toString ( ) , {
6057 method : 'GET' ,
6158 headers : {
59+ 'Authorization' : `Bearer ${ this . apiKey } ` ,
6260 'Accept' : 'application/json' ,
6361 'User-Agent' : 'Twitter-MCP-Server/1.0'
6462 }
@@ -72,51 +70,68 @@ export class SocialDataClient {
7270 }
7371
7472 async searchTweets ( options : SearchOptions ) : Promise < TweetSearchResponse > {
75- return this . makeRequest ( '/twitter/search' , {
76- query : options . query ,
77- count : options . maxResults || 10 ,
78- start_time : options . startTime ,
79- end_time : options . endTime
80- } ) ;
73+ const params : Record < string , any > = {
74+ query : options . query
75+ } ;
76+
77+ // Add optional parameters only if provided
78+ if ( options . startTime ) params . start_time = options . startTime ;
79+ if ( options . endTime ) params . end_time = options . endTime ;
80+
81+ const result = await this . makeRequest ( '/twitter/search' , params ) ;
82+
83+ // Transform response to match our expected format
84+ return {
85+ data : result . tweets || [ ] ,
86+ meta : {
87+ result_count : result . tweets ?. length || 0 ,
88+ next_token : result . next_token
89+ }
90+ } ;
8191 }
8292
8393 async getUserProfile ( options : UserSearchOptions ) : Promise < UserProfileResponse > {
84- const endpoint = options . username ? '/twitter/user/profile' : '/twitter/user/profile_by_id' ;
85- const param = options . username ? { username : options . username } : { user_id : options . userId } ;
86-
87- return this . makeRequest ( endpoint , {
88- ...param ,
89- include_metrics : options . includeMetrics || true
94+ // Use search to get user data as a fallback since direct profile endpoints may have issues
95+ const searchQuery = `from:${ options . username || options . userId } ` ;
96+ return this . makeRequest ( '/twitter/search' , {
97+ query : searchQuery ,
98+ count : 1
9099 } ) ;
91100 }
92101
93102 async getUserTweets ( options : UserSearchOptions & { maxResults ?: number } ) : Promise < TweetSearchResponse > {
94- const endpoint = '/twitter/user/tweets' ;
95- const param = options . username ? { username : options . username } : { user_id : options . userId } ;
96-
97- return this . makeRequest ( endpoint , {
98- ...param ,
99- count : options . maxResults || 10
103+ // Use search with from: operator to get user tweets
104+ const searchQuery = `from:${ options . username || options . userId } ` ;
105+ const result = await this . makeRequest ( '/twitter/search' , {
106+ query : searchQuery
100107 } ) ;
108+
109+ return {
110+ data : result . tweets || [ ] ,
111+ meta : {
112+ result_count : result . tweets ?. length || 0 ,
113+ next_token : result . next_token
114+ }
115+ } ;
101116 }
102117
103118 async getFollowers ( options : UserSearchOptions & { maxResults ?: number } ) : Promise < any > {
104- const endpoint = '/twitter/user/followers' ;
105- const param = options . username ? { username : options . username } : { user_id : options . userId } ;
106-
107- return this . makeRequest ( endpoint , {
108- ... param ,
109- count : options . maxResults || 100
110- } ) ;
119+ // This may not be available via search - will need specific endpoint
120+ // For now, return mock data indicating limitation
121+ return {
122+ data : [ ] ,
123+ meta : { result_count : 0 } ,
124+ note : 'Followers data requires specific API endpoint access'
125+ } ;
111126 }
112127
113128 async getFollowing ( options : UserSearchOptions & { maxResults ?: number } ) : Promise < any > {
114- const endpoint = '/twitter/user/following' ;
115- const param = options . username ? { username : options . username } : { user_id : options . userId } ;
116-
117- return this . makeRequest ( endpoint , {
118- ... param ,
119- count : options . maxResults || 100
120- } ) ;
129+ // This may not be available via search - will need specific endpoint
130+ // For now, return mock data indicating limitation
131+ return {
132+ data : [ ] ,
133+ meta : { result_count : 0 } ,
134+ note : 'Following data requires specific API endpoint access'
135+ } ;
121136 }
122137}
0 commit comments