【问题标题】:Twitter OAUTH Acces Token Response in JSONJSON 中的 Twitter OAUTH 访问令牌响应
【发布时间】:2016-10-22 22:32:09
【问题描述】:

我正在使用 Twitter 的 REST API 来授权应用程序。我刚刚使用

授权了该应用

https://api.twitter.com/oauth/authorize

并从重定向 uri 中获得 oauth_verifier。

那我就用了

https://api.twitter.com/oauth/access_token

获取 access_token。

问题是我从这个方法得到的响应格式是text/plain。就像

oauth_token=783897656863051776-5hQfcJTv4FzFpPcyVRbnjPUbJXR29&oauth_token_secret=MViTPOOCaHNZrW6HTIFZ340bq1rutJKL8oqkBxRp2aiW&user_id=783897656863051776&expiresname=s=s

我的问题是如何在application/json format 中获得响应。 任何帮助将不胜感激!!!

【问题讨论】:

  • 您真的想与我们所有人分享您的令牌、秘密和身份吗? :)
  • 不是原创!

标签: json api twitter oauth twitter-oauth


【解决方案1】:

您需要像 application/x-www-form-urlencoded 内容一样解析它,任何带有 HTTP 客户端库的语言都应该提供此功能。但不清楚您使用的是什么语言和库。

这个example使用joauth库来解析

  protected static Map<String, String> parseTokenMap(String tokenDetails) {
    KeyValueHandler.SingleKeyValueHandler handler =
        new KeyValueHandler.SingleKeyValueHandler();

    KeyValueParser.StandardKeyValueParser bodyParser =
        new KeyValueParser.StandardKeyValueParser("&", "=");
    bodyParser.parse(tokenDetails, Collections.singletonList(handler));

    return handler.toMap();
  }

【讨论】:

  • 那你的目标是什么?了解手动完成的全套命令吗?在没有客户的情况下提交一些请求?
  • 谢谢 :) 节省了我的时间!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-28
  • 2011-03-26
  • 2019-09-16
  • 2011-04-10
  • 2011-05-26
  • 2018-07-13
相关资源
最近更新 更多