使用Linq2Twitter和缓存OAuth凭证withing一个ServiceStack API [英] Using Linq2Twitter and cached OAuth tokens withing a ServiceStack api
问题描述
我想用Linq2Twitter使从写在ServiceStack一个REST API中的一个Twitter API调用
I want to use Linq2Twitter to make a Twitter API call from within a REST API written in ServiceStack.
我有以下信息:
- ConsumerKey
- ConsumerSecret
- 缓存的OAuth令牌从用户验证我们的应用程序在该网站
- 缓存的OAuth TokenSecret从用户身份验证的网站上我们的应用程序
- ConsumerKey
- ConsumerSecret
- cached OAuth Token from when the user authenticated our app on the site
- cached OAuth TokenSecret from when the user authenticated our app on the site
我如何使用该信息来创建TwitterContext这样我就可以进行API调用?我在看文件,我看到的WebForm,MVC,桌面例子,但是没有我现在的用例。我不认为我可以使用Web窗体/ MVC的人因为这些会尝试将用户重定向到一个授权页面如果令牌/令牌密钥是坏的。我看着桌面例子,它采用了针的授权,我不认为我可以使用。
How do I create the TwitterContext using this information so that I can make API calls? I am looking at the documentation and I see WebForm, MVC, Desktop examples, but none for my current use case. I don't think I can use the WebForm/MVC ones as those will try to redirect the user to an authorization page if the token/token secret are bad. I looked at the desktop example and it uses a pin authorization, which I don't think I can use either.
据我所知,令牌/令牌密钥可能是坏如果用户决定后,我已经缓存这些值来撤销访问,所以我需要一种方法来验证,然后做什么,如果它失败。
I understand that the token/token secret may be bad if the user decides to revoke access after I have cached these values, so I would need a way to verify and then do nothing if it fails.
推荐答案
这问题不完全一样,但授权人的概念可能是有趣的你:
This question isn't exactly the same, but the authorizer concept might be interesting to you:
从本质上讲,你要实例化一个授权人,全权证书属性分配值,如:
Essentially, you want to instantiate an authorizer, assigning values to the Credentials property, like this:
var auth = new SingleUserAuthorizer
{
Credentials = new SingleUserInMemoryCredentials
{
ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"],
TwitterAccessToken = ConfigurationManager.AppSettings["twitterAccessToken"],
TwitterAccessTokenSecret = ConfigurationManager.AppSettings["twitterAccessTokenSecret"]
}
};
然后,实例化TwitterContext,像这样的:
Then, instantiate your TwitterContext, like this:
var ctx = new TwitterContext(auth);
的特定授权人,在这种情况下,是SingleUserAuthorizer但你可以使用你用来得到相同的授权人原始凭据。只需提供全部4个凭据和LINQ to Twitter将绕过用户重新定向为在Twitter上的授权。
The particular authorizer, in this case, is SingleUserAuthorizer but you can use the same authorizer you used to get the original credentials. Just provide all 4 credentials and LINQ to Twitter will bypass the user re-direct for authorization on Twitter.
这篇关于使用Linq2Twitter和缓存OAuth凭证withing一个ServiceStack API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!