yikart/AiToEarn · error · TwitterPlatformException
Twitter user profile not found
Error message
Twitter user profile not found
What it means
getUserInfo fetches the authenticated Twitter user via GET /2/users/me with user fields. If the API response contains no user object, TwitterPlatformException('Twitter user profile not found') is thrown, indicating the platform did not return a profile for the given access token.
Source
Thrown at project/aitoearn-backend/apps/aitoearn-server/src/core/channels/platforms/twitter/twitter.service.ts:194
platformUid: string
displayName: string
avatarUrl?: string
username?: string
followersCount?: number
followingCount?: number
tweetCount?: number
}> {
const response = await this.runApiClientOperation({
accessToken,
endpoint: 'GET /2/users/me',
call: client => client.users.getMe({
userFields: ['id', 'name', 'profile_image_url', 'username', 'public_metrics'],
}),
})
const user = response.data
if (!user) {
throw new TwitterPlatformException('Twitter user profile not found')
}
const { followersCount, followingCount, tweetCount } = user.publicMetrics ?? {}
return {
platformUid: user.id,
displayName: user.name,
avatarUrl: user.profileImageUrl,
username: user.username,
followersCount,
followingCount,
tweetCount,
}
}
async createPost(
accessToken: string,
params: {
text: string
mediaIds?: string[]View on GitHub (pinned to d3aa8bea5b)
Solutions
- Re-authenticate the channel to obtain a fresh access token
- Check the Twitter API response details/logs for an underlying error (401/403) instead of missing data
- Confirm the token scope includes users.read / tweet.read
- Verify the account is not suspended or deleted
Example fix
// before
const user = response.data
if (!user) {
throw new TwitterPlatformException('Twitter user profile not found')
}
// after
const user = response.data
if (!user) {
this.logger.warn(`Twitter /users/me returned no data, response.errors=${JSON.stringify(response.errors)}`)
throw new TwitterPlatformException('Twitter user profile not found')
} Defensive patterns
Strategy: try-catch
Validate before calling
const canFetchProfile = (c: { accessToken?: string | null }) => typeof c.accessToken === 'string' && c.accessToken.length > 0 Type guard
function hasProfile(u: unknown): u is { id: string; name: string; profileImageUrl?: string } {
return !!u && typeof u === 'object' && 'id' in u
} Try / catch
try {
const info = await twitterService.getUserInfo(token)
} catch (e) {
if (String(e?.message).includes('user profile not found')) {
await channelService.requestReauth(channelId)
return
}
throw e
} Prevention
- Refresh access tokens before expiry
- Re-auth channels on first profile-not-found error
- Check token scopes at connection time
- Log underlying Twitter API errors for diagnosis
When it happens
Trigger: Calling getUserInfo with an expired/revoked access token, a token whose scope lacks users.read, or a Twitter API response missing data due to platform errors or deleted/suspended account.
Common situations: Stale channel credentials after the user revoked the app, partially completed OAuth flow, token obtained for a different Twitter API project with restricted scopes.
Related errors
- ChannelAuthRefreshTokenMissing
- ChannelAuthRefreshTokenMissing
- ChannelAuthPlatformUidMissing
- ChannelAuthRefreshTokenMissing
- 无效的账号或刷新令牌丢失
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/895ce040a66b1ceb.
Report an issue: GitHub.