Storing Twitter access token using Twitterizer

ε祈祈猫儿з 提交于 2019-12-12 09:26:44

问题


I'm trying to store Twitter access token to my database for a specific user, so he doesn't need to approve the application every time he wants to post a new tweet.

I can easily get user access token using Twitterizer, and what I get is OAuthTokenResponse object. It consists of several properties, but for each request (eg. posting a tweet) it asks for OAuthTokenResponse object, so it looks like its not enough to store the Token property only?

What's the best way to store this AccessToken? Thanks!


回答1:


You should store the 4 properties returned by the OAuthUtility.GetAccessToken method in your database. All authorized API calls require an OAuthTokens object. All you need to do is instantiate a new object, set the properties to the values you have (consumer token and access token), then pass your instance to the method.

For example:

OAuthTokens tokens = new OAuthTokens();
tokens.AccessToken = "XXX";
tokens.AccessTokenSecret = "XXX";
tokens.ConsumerKey = "XXX";
tokens.ConsumerSecret = "XXX";

TwitterResponse<TwitterUser> showUserResponse = TwitterUser.Show(tokens, "twit_er_izer");

Or, if you're using VB.NET:

Dim tokens As New OAuthTokens()
tokens.AccessToken = "XXX"
tokens.AccessTokenSecret = "XXX"
tokens.ConsumerKey = "XXX"
tokens.ConsumerSecret = "XXX"

Dim showUserResponse As TwitterResponse(Of TwitterUser) = TwitterUser.Show(tokens, "twit_er_izer")


来源:https://stackoverflow.com/questions/7470549/storing-twitter-access-token-using-twitterizer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!