JSON 中的 Twitter OAUTH 访问令牌响应
Twitter OAUTH Acces Token Response in JSON
我正在使用 Twitter 的 REST API 来授权应用程序。我刚刚使用
授权了该应用
并从重定向 uri 中得到一个 oauth_verifier。
然后我就用了
获得access_token。
问题是我从这个方法得到的响应格式是text/plain
。就像
oauth_token=783897656863051776-5hQfcJTv4FzFpPcyVRbnjPUbJXR29&oauth_token_secret=MViTPOOCaHNZrW6HTIFZ340bq1rutJKL8oqkBxRp2aiW&user_id=783897656863051776&screen_name=sWest&x_auth_expires=0
我的问题是如何在 application/json format
中获得响应。
任何帮助将不胜感激!!!
您需要像 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();
}
我正在使用 Twitter 的 REST API 来授权应用程序。我刚刚使用
授权了该应用并从重定向 uri 中得到一个 oauth_verifier。
然后我就用了
获得access_token。
问题是我从这个方法得到的响应格式是text/plain
。就像
oauth_token=783897656863051776-5hQfcJTv4FzFpPcyVRbnjPUbJXR29&oauth_token_secret=MViTPOOCaHNZrW6HTIFZ340bq1rutJKL8oqkBxRp2aiW&user_id=783897656863051776&screen_name=sWest&x_auth_expires=0
我的问题是如何在 application/json format
中获得响应。
任何帮助将不胜感激!!!
您需要像 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();
}