English 中文(简体)
从 Javascript 网站的 Tweet 输入字段
原标题:Tweet input field from website in Javascript

我的网页上有一个输入字段,我想允许用户在推特上发推特。我知道我可以使用Oauth,但因为我在使用JavaScript,所以它不安全,因为我的ID和秘密是可见的。是否有更好的办法做到这一点?

我现在这样做的方式是这样的:

var accessor = {
  token: "...",
  tokenSecret: "...",
  consumerSecret: "..."
  consumerKey : "...",
};

  //create message with input field text
  var message = {
  action: url,
  method: "GET",
  parameters: {...}
};

OAuth.completeRequest(message, accessor);        
OAuth.SignatureMethod.sign(message, accessor);
url = url +  ?  + OAuth.formEncode(message.parameters);

但这会让我的秘密变得显眼

谢谢 谢谢

最佳回答

在OAuth模式中,有三个当事方:服务器或“资源经理”、“应用程序”或“客户”以及用户或“资源所有人”。

在您的情况中, “ 客户” 是网络应用程序, 您正在建设的东西。 资源管理者是 Twitter, 用户是资源所有者 。 也许值得重复: 拥有和管理的“ em> resources < / em” 是推特流 。

OAuth 允许客户代表资源所有者向资源经理提交申请。 与您的情况相比, 您的应用程序( 网络应用程序) 可以代表用户提交推文 。

网络应用程序模型及其分布式计算模型,服务器上运行一些代码(PHP、Ruby、ASPNET或不管它是什么),客户端上运行一些代码(Javascript),使问题略为混淆。

正如你指出的,你可以通过在JS代码中嵌入密钥和秘密来“做” Ousth。你正确地指出,这暴露了您不想揭露的东西。

The obvious alternative is to embed that stuff into the server-side code. This requires that the connection to twitter occur between the server and twitter, not between the browser and twitter. When the user wants to tweet, use an ajax call from the browser to a piece of code on your server, let s call it mytweet.php. This is a script you write, which then does the OAuth dance and sends a status update to twitter.com on behalf of the user.

是这样吗?

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签