JavaScript: Get user email address using user id and creator access token

Hi,

I’m trying to get a user (pledger) email address using the user id. Here is my code:

 request.get(`https://www.patreon.com/api/oauth2/v2/members/${users[i].id}`, {
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'Authorization': 'Bearer ' + access_token
                },
                json: {
                }
            }, (error, res, body) => {
                if (error) {
                    console.error(error)
                    return
                }
                console.log(`statusCode: ${res.statusCode}`)
                console.dir(body)

            })

I receive status code 200 with a data object but it only contains id and type. How do I get the email address? I’ve seen you can do it with python but the npm module doesn’t seem to have much functionality.

Thanks

To get the resources in api v2, you must have the scopes assigned to your token while you are requesting the token. And then ask them specifically with includes.

For example, to get the email, you must have acquired the user token (if you are doing it over a user’s token) with email scope. Then you request the email in the include.

Or if you are doing it with creator token, you must specifically request the email in the include.

The PHP lib has an example in the readme that illustrates the way to request email scope during token creation (login).

fetch_user function has the code to request the email via includes when you are asking for user details:

The eamples folder also has various examples using how you can use the return.

1 Like

@codebard ok thanks I’ll have a look at that

1 Like