如何在Web服务中使用Linq to Twitter? [英] How to use Linq to Twitter inside a web service?

查看:113
本文介绍了如何在Web服务中使用Linq to Twitter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用Linq到Twitter的Web应用程序,以帮助用户管理Twitter帐户.我知道我需要在服务器端隐藏我的使用者密钥和使用者秘密,以防止它被暴露.

I'm writing a web app that uses Linq to Twitter to help a user manage a Twitter account. I understand that I need to hide my consumer key and consumer secret on the server side to prevent it from being exposed.

为此,我知道我可以使用MvcAuthorizer并在我的MVC应用程序的服务器端使用Linq To Twitter.但是,如果我想从Web应用程序中分离Linq To Twitter代码并将其作为与MVC应用程序分开托管的Web服务公开,怎么办?

In order to do this, I know that I could use the MvcAuthorizer and use Linq To Twitter up on the server side of my MVC Application. But what if I wanted to separate the Linq To Twitter code from the web app and expose it as a web service hosted separately from my MVC app?

所以数据流看起来像这样...

So the data flow would look like this...

Web浏览器客户端<->我的Web服务(ServiceStack)<-> Linq to Twitter<-> Twitter REST API

Web Browser Client <--> My Web Service (ServiceStack) <--> Linq to Twitter <--> Twitter REST API

通过阅读Linq to Twitter和dev.twitter.com网站上的文档,我的理解是我的流程应该像这样.

From reading the documentation on both the Linq to Twitter and dev.twitter.com site, my understanding is that my process flow should look something like this..

  1. 用户单击Web应用程序中的某些按钮以启动授权过程
  2. 用户被重定向到Twitter,并授权该应用程序使用.
  3. 用户被重定向回我指定的回调URL.我的应用现在可以通过该回调URL中的查询字符串访问用户的OAuth令牌
  4. 我的应用将这些OAuth令牌存储在某个地方
  5. 我的代理Web服务使用这些OAuth令牌代表用户查询Twitter API.

我认为我可以使用我不确定如何完成5.我的想法是收到发送给服务的UserTweetsRequest消息.该消息将指定Twitter用户名.在服务内部,我将为该用户查找存储的OAuth令牌,将其与我的消费者令牌结合起来,然后使用Linq To Twitter进行查询.

I'm not sure how to accomplish 5. My thought was to have a UserTweetsRequest message that I sent to my service. The message would specify the Twitter username. Inside the service, I'd look up the stored OAuth tokens for that user, combine them with my consumer tokens, then use Linq To Twitter to make the query.

如果我现在拥有所有消费者和用户令牌,则需要通过Linq to Twitter调用Twitter API,我应该在服务实现中使用哪个Authorizer来实现这一目标?我需要自己实现吗?

If I now have all of the consumer and user tokens I need to call the Twitter API via Linq to Twitter, which Authorizer should I use inside my service implementation to make that happen? Do I need to implement my own?

推荐答案

如果您拥有全部4个密钥,则LINQ to Twitter授权者将绕过Twitter授权过程并仅签署请求.听起来就是这样,因此您可以(几乎)使用Web Service中的任何授权者.只要提供所有4个凭据,就可以使用SingleUserAuthorizer,MvcAuthorizer或WebAuthorizer.

The LINQ to Twitter authorizers are designed to bypass the Twitter authorization process and just sign a request, if you have all 4 keys. It sounds like that is the case, so you can use (almost) any of the authorizers in your Web Service. You could use SingleUserAuthorizer, MvcAuthorizer, or WebAuthorizer as long as you provide all 4 credentials.

我在示例页面.您可能需要使用该示例将LINQ的版本更新到Twitter,但查看它可能会很有用.

I have a WCF demo on my Samples Page. You will probably need to update the version of LINQ to Twitter with the sample, but it might be useful to look at.

这篇关于如何在Web服务中使用Linq to Twitter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆