无法让 irb 控制台与 tumblr_client gem 一起工作 [英] Not able to get irb console working with tumblr_client gem

查看:61
本文介绍了无法让 irb 控制台与 tumblr_client gem 一起工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 API 的经验很少,我正试图改变这一点,所以我正在尝试开始使用 Tumblr api.我已经安装了 tumblr_client gem(此处的文档)并按照说明进行操作.我在一个新的 Tumblr 帐户上创建了一个应用程序,并拥有必要的 OAuth 信息(consumer_key、c​​onsumer_secret 等).实际上让它做某事很困难,所以像一个优秀的小程序员一样,我试图让控制台运行探索一下.

I have very little experience with APIs which is something that I'm trying to change so I'm trying to get started with the Tumblr api. I've installed the tumblr_client gem (documentation here) and am following the instructions. I've created an application on a new Tumblr account and have the necessary OAuth information (consumer_key, consumer_secret, ect.) Actually getting it to do something is proving difficult, so like a good little programmer I'm trying to get the console going to explore a bit.

这需要一些设置,所以我按照这里的说明进行操作:

This requires a bit of setup, so I'm following the instructions here:

第一次去使用irb控制台,如果你没有.tumblr 文件,它将引导您完成生成一个的过程.系统将提示您输入 consumer_key 和 consumer_secret(其中你可以到这里:http://www.tumblr.com/oauth/register) 然后发送到网站验证您的帐户.验证后,您将重定向到您的重定向 URL(默认为 localhost)并复制oauth_verifier 回到控制台.那么你就准备好了!

The first time that you go to use the irb console, if you have no .tumblr file, it will walk you through the process of generating one. You will be prompted for your consumer_key and consumer_secret (which you can get here: http://www.tumblr.com/oauth/register) and then sent out to the site to verify your account. Once you verify, you will be redirected to your redirect URL (localhost by default) and copy the oauth_verifier back into the console. Then you're all set!

系统提示我输入我的密钥和机密,然后我转到我应该授予授权的 URL.Tumblr 给了我一个弹出窗口,上面写着这个应用程序可以访问你的一些数据并发布到你的帐户吗?你以 example@example.com 的身份登录"以及取消或允许的选项.我点击了允许,它只会让我进入帐户本身,我从来没有给过任何可以输入的验证码来让控制台正常工作.

I'm prompted for my key and secret, then I go to the URL where I'm supposed to give authorization. Tumblr gives me a popup which reads "Is it alright for this application to access some of your data and make posts to your account? You are logged in as example@example.com" and the options to cancel or allow. I hit allow and it just takes me into the account itself, at no point am I ever given any kind of verification code that I can put in to get the console working.

此时我卡住了,不能再继续了,所以我正在激活网络.关于我哪里出错的任何想法?

At this point I'm stuck and can't go any further so I'm activating the network. Any ideas as to where I'm going wrong?

推荐答案

您是否在 oauth 配置过程中的任何时候指定了重定向或回调 URL?它可能是在 tumblr 的 API 网站上完成的.此 url 将是您的应用程序的端点,Tumblr 将用户数据请求发送到该端点.顺便说一下,oauth 设置有时会令人困惑.例如,您将无法使用 localhost 作为回调 url,但您可以使用免费的本地隧道应用程序获取临时域名.

Did you specify a redirect or callback url at any point in the oauth config process? It's probably done on tumblr's API website. This url would be your app's endpoint to which Tumblr sends a request to with the user's data. By the way, oauth can sometimes be confounding to set up. You won't be able to use localhost as a callback url, for example, though you can get a temporary domain name with a free local tunneling app.

编辑要更详细地了解其中一些要点...

edit To go into more detail on some of these points ...

  • 回调网址:重申一下,这不能是本地主机.设置正确的回调 url 将使您摆脱当前的困境.您希望确认页面重定向到您的应用程序,而不是重定向到 tumblr 主页.无论如何,我认为您在部署之前想要对其进行测试是完全明智的.但是,除非您部署或使用本地隧道,否则您的本地应用程序实际上没有可以从您的计算机以外的任何地方访问的 URL.
  • 本地隧道服务:ngrok本地隧道.举一个 ngrok 的例子:假设你有一个运行在端口 3000 上的 Rails 服务器.然后在另一个终端中你运行 ngrok 3000 并且你得到一个 url,它将你的本地服务器暴露给真实的互联网.请注意,每次重新启动 ngrok 时都会发生变化(除非您付费).在您的应用程序中,您应该为回调创建一个唯一的路由.假设您有一个将 /oauth_callback 匹配到 oauth_callback 控制器操作的路由.那么您作为回调 url 提供的路由将是 http://MY_CUSTOM_NAME.ngrok.com/oauth_callback.
  • 控制器动作:我不知道 Tumblr 如何将用户数据发送到回调.也许信息在标题中,也可能在正文中.它可能是 JSON 或 XML.无论是什么,您都可以通过在控制器操作中放置断点来探索数据.您可以检查 paramsheaders 等.我希望他们会给您一些令牌凭据,可能还会提供用户名/电子邮件.
  • callback url: To reiterate, this cannot be localhost. Setting the correct callback url will get you unstuck from your current predicament. Instead of redirecting to the tumblr homepage, you want the confirmation page to redirect to your app. Anyway, I think you're totally sensible to want to test it out before you deploy. But unless you deploy or use a local tunnel, your local application doesn't actually have a URL that can be reached from anywhere except your computer.
  • local tunnelling services: ngrok, localtunnel. To give an example with ngrok: Say you have a Rails server running on port 3000. Then in another terminal you run ngrok 3000 and you get a url which exposes your local server to the real internet. Note that this changes every time you restart ngrok (unless you pay them). In your application, you should make a unique route for the callback. Say you have a route which matches /oauth_callback to the oauth_callback controller action. Then the route you'd provide as your callback url would be http://MY_CUSTOM_NAME.ngrok.com/oauth_callback.
  • The controller action: I don't specifically know how Tumblr sends user data to the callback. Perhaps the information is in the headers or maybe it's in the body. It might be JSON or XML. Whatever it is, you can explore the data by placing a breakpoint in your controller action. You can inspect the params, headers, etc. I'd expect that they'd give you some token credentials and probably a user name/email as well.

这篇关于无法让 irb 控制台与 tumblr_client gem 一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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