WhiskeySockets / Baileys

Lightweight full-featured typescript/javascript WhatsApp Web API
https://baileys.whiskeysockets.io/
MIT License
4.1k stars 1.38k forks source link

[BUG] fetching profile picture (not-authorized) #1073

Closed benaysuman closed 1 month ago

benaysuman commented 1 month ago

Describe the bug when retrieving profile pictures alot of the profile pictures you try to retrieve return the error not authorized even when trying with different phone numbers

To Reproduce Steps to reproduce the behavior: in chats.js

const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
    var _a;
    try {
        jid = (0, WABinary_1.jidNormalizedUser)(jid);
        console.log(`Fetching profile picture for JID: ${jid}`);

        const result = await query({
            tag: 'iq',
            attrs: {
                target: jid,
                to: WABinary_1.S_WHATSAPP_NET,
                type: 'get',
                xmlns: 'w:profile:picture'
            },
            content: [
                { tag: 'picture', attrs: { type, query: 'url' } }
            ]
        }, timeoutMs);

        console.log(`Query result:`, result);

        const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
        const url = (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;

        console.log(`Profile picture URL: ${url}`);
        return url;

    } catch (error) {
        console.error(`Error fetching profile picture for JID: ${jid}`, error);
        return null;  // Return null or handle it in another way
    }
};

then start retrieving profile pictures and you will see alot of not-authorized errors

Expected behavior it should either return no-item or the picture expected

Environment (please complete the following information):

Additional context none

vinikjkkj commented 1 month ago

not-authorized is emitted when user not have profile picture

bobslavtriev commented 1 month ago

not authorized is when the photo is for contacts only (you are not authorized to view it)

item not found is when there is no photo

benaysuman commented 1 month ago

but when I add the number on my phone I can see the picture so thats false

hacxk commented 1 month ago

NO If u try to Get a Profile Picture of a Community/Group But u not a Admin it will Throw not-authorized Error

PurpShell commented 1 month ago

missing log info