Skip to content

Commit 315240d

Browse files
author
Uros Marolt
authored
Fixed an issue that occurred when fetching twitter followers. (#270)
1 parent 18c6b42 commit 315240d

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

backend/src/serverless/integrations/services/integrations/twitterIntegrationService.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export class TwitterIntegrationService extends IntegrationServiceBase {
6161
stream: IIntegrationStream,
6262
context: IStepContext,
6363
): Promise<IProcessStreamResults> {
64+
const log = this.logger(context)
65+
6466
const { fn, arg } = TwitterIntegrationService.getUsecase(
6567
stream.value,
6668
context.pipelineData.profileId,
@@ -85,6 +87,19 @@ export class TwitterIntegrationService extends IntegrationServiceBase {
8587
: undefined
8688
const sleep = limit <= 1 ? timeUntilReset : undefined
8789

90+
if (records === undefined) {
91+
log.error(
92+
{
93+
stream: stream.value,
94+
page: stream.metadata.page,
95+
profileId: context.pipelineData.profileId,
96+
},
97+
'No records returned!',
98+
)
99+
100+
throw new Error(`No records returned for stream ${stream.value}!`)
101+
}
102+
88103
if (records.length === 0) {
89104
return {
90105
operations: [],

backend/src/serverless/integrations/usecases/slack/getMember.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@ async function getMembers(
2121

2222
const response = await axios(config)
2323
const member = response.data.user
24-
const limit = 100
25-
const timeUntilReset = 0
2624
const nextPage = response.data.response_metadata?.next_cursor || ''
2725
return {
2826
records: member,
2927
nextPage,
30-
limit,
31-
timeUntilReset,
3228
}
3329
} catch (err) {
3430
if (err && err.response && err.response.status === 429 && err.response.headers['Retry-After']) {

backend/src/serverless/integrations/usecases/twitter/getFollowers.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from 'axios'
1+
import axios, { AxiosRequestConfig } from 'axios'
22
import moment from 'moment'
33
import { TwitterGetFollowersInput, TwitterGetFollowersOutput } from '../../types/twitterTypes'
44
import { Logger } from '../../../../utils/logging'
@@ -13,17 +13,30 @@ const getFollowers = async (
1313
logger: Logger,
1414
): Promise<TwitterGetFollowersOutput> => {
1515
try {
16-
const config = {
16+
const config: AxiosRequestConfig<any> = {
1717
method: 'get',
18-
url: `https://api.twitter.com/2/users/${input.profileId}/followers?user.fields=name,description,location,public_metrics,url,verified,profile_image_url&pagination_token=D903MLRBG6U1EZZZ`,
18+
url: `https://api.twitter.com/2/users/${input.profileId}/followers`,
19+
params: {
20+
'user.fields': 'name,description,location,public_metrics,url,verified,profile_image_url',
21+
},
1922
headers: {
2023
Authorization: `Bearer ${input.token}`,
2124
},
2225
}
26+
27+
if (input.perPage) {
28+
config.params.max_results = input.perPage
29+
}
30+
31+
if (input.page) {
32+
config.params.pagination_token = input.page
33+
}
34+
2335
const response = await axios(config)
2436
const limit = parseInt(response.headers['x-rate-limit-remaining'], 10)
2537
const resetTs = parseInt(response.headers['x-rate-limit-reset'], 10) * 1000
2638
const timeUntilReset = moment(resetTs).diff(moment(), 'seconds')
39+
2740
return {
2841
records: response.data.data,
2942
nextPage: response.data.meta.next_token || '',

0 commit comments

Comments
 (0)