嗨,我正在尝试从 google apis 获取请求令牌。为了获取请求令牌,我必须通过字符串的 Java 代码段中的字典字节值排序来对参数字符串进行排序
String datastring=URLEncoder.encode("oauth_version", "UTF-8")+"="+URLEncoder.encode("1.0", "UTF-8");
datastring+="&"+URLEncoder.encode("oauth_nonce", "UTF-8")+"="+URLEncoder.encode(System.currentTimeMillis()+"","UTF-8");
datastring+="&"+URLEncoder.encode("oauth_timestamp", "UTF-8")+"="+URLEncoder.encode(System.currentTimeMillis()/1000+"","UTF-8");
datastring+="&"+URLEncoder.encode("oauth_consumer_key","UTF-8")+"="+URLEncoder.encode("iriteshmehandiratta.appspot.com","UTF-8");
datastring+="&"+URLEncoder.encode("oauth_signature_method","UTF-8")+"="+URLEncoder.encode("RSA-SHA1", "UTF-8");
datastring+="&"+URLEncoder.encode("oauth_signature", "UTF-8")+"="+URLEncoder.encode(myrsakey, "UTF-8");
datastring+="&"+URLEncoder.encode("oauth_callback","UTF-8")+"="+URLEncoder.encode("https://www.iriteshmehandiratta.appspot.com/authsub","UTF-8");
datastring+="&"+URLEncoder.encode("scope","UTF-8")+"="+URLEncoder.encode("http://www.google.com/calendar/feeds","UTF-8");
我对查询字符串的参数进行了编码,现在我必须按字典顺序对数据字符串进行排序,以便将发布请求发送到 URL https://www.google.com/accounts/OAuthGetRequestToken 任何人都可以帮助如何在 Java 中按字典顺序对这个字符串进行排序。