twittertwitter-oauthaccess-tokenuseridlinq-to-twitter

Is it possible to retrieve the Twitter userid of a user from the access token?


Let me explain my problem, currently I use LinqToTwitter to perform the authorization of a user.

I have the Connect Twitter button on my website, when the user click on it, an ajax request requests the method to perform authorization, the user is redirect to :

"https://api.twitter.com/oauth/authorize?oauth_token=" 

and then enter his login and password.

Once it's done, he is redirect to the urlReferrer of my website and I receive the fields I need like username, userid, ....

Then if the UserId of the social network user doesn't match with any entries of my database I open a popup to ask for his email ( Email is a required field)

Then, once the email has been confirmed by the user, I have to connect him in our website by making an ajax request connectSocialUser(userid, avatar, accessToken).

For Google and Facebook I have put in parameter the access token and then request respectively these two urls :

"https://graph.facebook.com/me?fields=id&access_token="
"https://www.googleapis.com/oauth2/v1/userinfo?access_token="

These two urls give me back the userid and by a simple comparison I can know that the user is the good one and not an usurper.

So my question is : Is it possible to retrieve the userid of a user from the access token ?

If not how can I make this works?

Thank you a lot!


Solution

  • As soon as you complete authorization, LINQ to Twitter will populate the auth.Credentials.UserId property. You can also find ScreenName there too.