Skip to content

How to get user_id or screen_name? #19

@jpurcell

Description

@jpurcell

A question was given:

What is the best way to retrieve the user_id?

Answer:

Currently, it's not supported, but will be implemented in v1.0. Here was my response:

First, you can just make an API call to:

https://dev.twitter.com/docs/api/1/get/users/show

(I think https://dev.twitter.com/docs/api/1/get/users/lookup is for batch lookups.)

Otherwise, you'll have to catch it when the request tokens are exchanged for access tokens:

https://dev.twitter.com/docs/auth/oauth#Exchanging_a_request_token_for_an_access_token

The user_id and screen_name are returned at that point. So, check around line 289 at the get_access_token function and you'll see something like:

cfg.user_id = responseParams['user_id'];
cfg.screen_name = responseParams['screen_name'];

Currently, the script doesn't save that information, though I think it should. Notice the save_access_token() function that is called just after the above code. That save function (line 367) only saves the access token and token secret. If you want to save the info you can do something like:

        // write config
        var config = {
            access_token: cfg.access_token,
            access_token_secret: cfg.access_token_secret,
            user_id: cfg.user_id,
            screen_name: cfg.screen_name
        };

Then add around line 1142 the following:

    this.screen_name = cfg.screen_name;
    this.user_id = cfg.user_id;

So, it's kinda confusing, but if you do the above right, you should be able to get the user_id by:

user_id = BH.user_id;

And same for screen_name. I'll add this post to the issues list and put it in for v1.0.

If you don't get the above to work, let me know and perhaps I can help.

Good luck!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions