- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试访问 1.0 版本的 Oauth 网络服务。我可以通过 postman 客户端成功完成这项工作,但无法在安卓应用。
使用的库:-路标-commonshttp4-1.2.1.2.jar
API 所需的参数:-oauth_consumer_keyoauth_nonceoauth_versionoauth_signatureoauth_signature_methodoauth_timestamp
代码:-
HttpClient httpclient = new DefaultHttpClient();
// generate the oauth_signature
String urlParamsForSignature = "oauth_consumer_key="+consumerKey +
"&oauth_nonce=" + "pT6c0H"+
"&oauth_signature_method=HMAC-SHA1" +
"&oauth_timestamp=" + timestamp +
"&oauth_version=1.0";
String baseString = "https://oauth.withings.com/account/request_token?" + urlParamsForSignature;
String signature = computeHmac(URLEncoder.encode(baseString), consumerSecret);
// add it to params list
qparams.add(new BasicNameValuePair("oauth_signature", signature));
// generate URI which lead to access_token and token_secret.
String urlParams = "oauth_consumer_key="+consumerKey +
"&oauth_nonce=" + "pT6c0H"+
"&oauth_signature=" + signature +
"&oauth_signature_method=HMAC-SHA1" +
"&oauth_timestamp=" + timestamp +
"&oauth_version=1.0";
String url = "https://oauth.withings.com/account/request_token?" + urlParams;
HttpGet httpget = new HttpGet(url);
// output the response content.
System.out.println("oken and Token Secrect:");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
int len;
byte[] tmp = new byte[2048];
while ((len = instream.read(tmp)) != -1) {
System.out.println(new String(tmp, 0, len, ENC));
}
}
public String computeHmac(String baseString, String key)
{
try {
Mac mac = Mac.getInstance("HmacSHA1");
SecretKeySpec secret = new SecretKeySpec(key.getBytes(), mac.getAlgorithm());
mac.init(secret);
byte[] digest = mac.doFinal(baseString.getBytes());
return new String(Base64.encodeBase64(digest));
} catch (InvalidKeyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
最佳答案
根据您发布的代码..您没有使用路标库来生成签名。您正在为此使用您的自定义代码。
您可以按如下方式使用路标库:
//create an oAuth consumer and provide CONSUMER_KEY & CONSUMER SECRET.
DefaultOAuthConsumer defaultOAuthConsumer = new DefaultOAuthConsumer("CONSUMER_KEY","CONSUMER_SECRET");
//REQUEST URL
String url = "https://oauth.withings.com/account/request_token";
try {
// sign the url with consumer. (This will add all oAuth parameters to the query automatically and return the signed request url with all parameter).
url = defaultOAuthConsumer.sign(url);
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
}
// use the url to make your request.
关于android - Postman Rest Client 如何创建 Oauth 签名?无法在 android 中解析 Oauth_Signature,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23760525/
我在 postman 的预请求脚本中有以下代码——它给了我当前日期。我宁愿想要昨天的日期(current_timestamp - 1 天)。 var current_timestamp = new D
Postman Pro 可以向多个 Free Postman 用户共享无限制的请求吗? 我正在考虑设置一个 Pro 帐户作为中央请求收集存储,然后 Free Postman 用户只需克隆/读取它即可。
有可能在 postman 内部使用数组变量吗? 例如在请求正文中: { "myData" : {{arrayVariable}} } 在数据文件中: { "arrayVariable"
我有一个 postman 集合,我想将一组三个 API 调用链接在一起,并使用 runner 函数提供数据文件。可以说他们是:/prepareUpload/upload/confirmUpload并且
如何从另一个 GET API 的预请求脚本选项卡调用 POST API 请求(登录 API 具有带用户名和密码字段的请求正文),该 API 在其请求 url 中使用来自上述 API 正文的 token
当前,可以从global和environment范围以及预请求脚本中的通用variable设置和获取变量。但是,文档尚不清楚,是否可以通过编程方式设置collection作用域变量。 例如 pm.en
我正在使用 postman (v7.7.3),当我上传文件以将正文作为表单数据发送时,我收到了以下警告。 “此文件不在您的工作目录中。与您共享此请求的队友将无法使用此文件。为了使协作更容易,您可以在“
standalone Postman client在哪里?对于 Windows,离线工作时保存集合吗? 为了澄清,我想找到禁用在线同步时 Postman 默认保存集合文件的位置。我不试图 export
我之前使用过 Postman Chrome 扩展以及 Postman Interceptor Extension在 Postman 中捕获 Chrome 发出的 HTTP 请求。 但是,现在 Post
在 Postman 中单击保存的请求后,我得到的 View 如下所示: 要查看正文,我需要单击“正文”。 这不是什么大问题,除非我要处理 20 个左右的请求,并在每个请求的正文中查找特定的内容,如果能
我正在查看 Postman 快捷方式面板,但没有看到在请求正文中注释部分代码的快捷方式,复制和粘贴非常烦人 发表评论。 最佳答案 根据快捷方式面板Ctrl +/打开快捷方式面板但我不小心在请求正文中这
是否可以在我的 postman 测试用例中访问响应大小的值? 虽然我能够看到响应大小以及状态代码和响应时间(我可以在使用responseCode.code和responseTime的测试用例中使用这两
我正在尝试使用 Windows native Postman 应用程序 (V4.8.0) 将简单的 Get 命令发布到我在本地主机上运行的服务,但它们失败了。 postman 控制台显示 Error:
Newman 帮助指定集合、环境和全局变量可以作为路径或 URL 传递。我可以看到如何从 Postman 获取收藏 URL(通过转到“共享”>“收藏链接”)。 如何在 Postman 中获取 Envi
我们正在扩展到一个大型微服务构建,并通过 postman 完成更多测试(现场验证、错误测试等)。好奇...您的团队如何组织大量 API 的集合? (按 API、按测试类型、按发布等)从一个团队传递到另
Postman 对我来说是一个了不起的工具,但我对使用变量有一些疑问。在我的收藏中,我有 4 个选项卡/请求。 首先是获取用于其他三个的 token ( token 在 15 分钟后过期,因此我必须经
由于所有 Postman 集合基本上都是 .json 文件,因此很难通过代码审查工具审查在 Postman 中编写的代码。 目前我继续在GitHub上查看这样的.json文件,但是不太方便。 例如,这
我正在尝试使用 Newman 自动化 postman 测试.授权有问题。授权 bearer token 发生变化并且是动态的。有谁知道如何自动执行此操作? 最佳答案 Postman 有变量这个很好的特
Postman 允许使用 pre-defined variables 生成随机虚拟数据,例如,这个将被随机公司名称替换: {{$randomCompanyName}} 多次使用预定义变量会在每个请
我正在使用一个开放的 API。 但我只使用了 API 提供的响应中的一小部分数据。当我使用具有不同参数的 API 进行测试以查看响应时。 我不想每次发送请求时都看到整个 API 响应,我只想看到我感兴
我是一名优秀的程序员,十分优秀!