Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get user_id or screen_name? #19

Open
jpurcell opened this issue Aug 2, 2011 · 2 comments
Open

How to get user_id or screen_name? #19

jpurcell opened this issue Aug 2, 2011 · 2 comments

Comments

@jpurcell
Copy link
Owner

jpurcell commented Aug 2, 2011

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!

@jpurcell
Copy link
Owner Author

jpurcell commented Aug 5, 2011

The following was suggested as an alternative. Add at line 1141:

this.cfg = cfg;

Then outside one can do something like:

oauth_token = BH.cfg.oauth_token;

@pankaj1984
Copy link

As we getting screen name and user_id from above code,Can you suggest how to fetch user image from twitter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants