getUserProfilePhotos
Returns: UserProfilePhotosOfficial docs ↗
Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
Parameters
user_idIntegerRequiredUnique identifier of the target user
offsetIntegerOptionalSequential number of the first photo to be returned. By default, all photos are returned.
limitIntegerOptional Default: 100min 1max 100Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100.
Returns
On success, the UserProfilePhotos object is returned.
GramIO Usage
ts
// Get all profile photos for a user:
const result = await bot.api.getUserProfilePhotos({
user_id: 12345678,
});
console.log(`User has ${result.total_count} profile photo(s)`);ts
// Check if a user has a profile photo in a message handler:
bot.command("photo", async (ctx) => {
if (!ctx.from) return;
const result = await bot.api.getUserProfilePhotos({
user_id: ctx.from.id,
limit: 1,
});
if (result.total_count === 0) {
return ctx.send("You don't have a profile photo set.");
}
// result.photos[0] is an array of PhotoSize objects (different sizes of the same photo)
const largestSize = result.photos[0][result.photos[0].length - 1];
await ctx.send(`Your latest profile photo file_id: ${largestSize.file_id}`);
});ts
// Paginate through profile photos in batches:
const page1 = await bot.api.getUserProfilePhotos({
user_id: 12345678,
offset: 0,
limit: 10,
});
console.log(`Showing 1–${page1.photos.length} of ${page1.total_count} photos`);
// Fetch next batch if more exist:
if (page1.total_count > 10) {
const page2 = await bot.api.getUserProfilePhotos({
user_id: 12345678,
offset: 10,
limit: 10,
});
console.log("Next page count:", page2.photos.length);
}Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: user not found | The user_id doesn't correspond to a known Telegram user — user must have started the bot or share a common chat |
| 429 | Too Many Requests: retry after N | Rate limit hit — check retry_after and back off |
TIP
Use GramIO's auto-retry plugin to handle 429 errors automatically.
Tips & Gotchas
- Each entry in
photosis an array ofPhotoSize. A single profile photo is provided in multiple resolutions. The last element in each inner array is always the largest — useresult.photos[0][result.photos[0].length - 1]to get the full-size version. total_countreflects all available photos, not just the current page. Use it alongsideoffsetandlimitto implement pagination: fetch the next page whenoffset + limit < total_count.- Photos are returned newest-first.
offset: 0gives the most recently set profile picture. - Requires the user to be accessible. A "user not found" error is returned if the user has never interacted with the bot and shares no common group — this is common for bots that try to look up arbitrary user IDs.
- Privacy settings may restrict results. Telegram users can restrict who can see their profile photos. The method may return fewer photos than
total_countsuggests if privacy settings apply. file_idfrom this method can be reused. Once you have afile_id, you can use it withsendPhotoor other send methods without re-downloading the file.
See Also
- UserProfilePhotos — return type with
total_countandphotosarray (array ofPhotoSize[]) - getUserProfileAudios — analogous method for profile audio files
- getMe — get the bot's own profile information