android - Twitter 更新/状态 API 正在使用邮递员而不是在代码 Android 中工作
问题描述
我在 Android 应用程序中集成 Twitter statuses/update.json API。我正在对 API 进行改造。此 API 是必需OAuth 1.0
的,我正在生成所有必需的值并调用 API,它给了我以下响应:
{"errors":[{"code":89,"message":"Invalid or expired token."}]}
当我在邮递员中传递所有必需的值时,它正在工作。
这是我将值传递给 Postman 的方式(form-urlencoded):
以下是我在代码中生成并传入标头的字符串Authorization
OAuth oauth_consumer_key="55pQiiN7hMwSEKMDqc0wYcH",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1617275741",oauth_nonce="675889204f9748a98a7f24c8c313d9bf",oauth_version="1.0",oauth_signature="vuH%2BpCkPNNEr9CnNzT6wXCj2k%3D",oauth_token="2997731-kzHvqPH2NeYnHOV6tFB1wtvXlk1qzUFk3pqUHA",oauth_token_secret="lDOo0Ozyjq2ngdGEr52IOPGxxbsXbWACxZEXLrvlcsO5p",oauth_consumer_secret="tqMmRHJ4kGbykxbOaYD1ZHJgfsKfFSCySpUOGpnIWWH6KjJ"
如上所述,它给了我一个错误。
我如何生成签名:
private static String computeSignature(String baseString, String keyString) throws GeneralSecurityException, UnsupportedEncodingException {
SecretKey secretKey = null;
byte[] keyBytes = keyString.getBytes();
secretKey = new SecretKeySpec(keyBytes, "HmacSHA1");
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(secretKey);
byte[] text = baseString.getBytes();
return new String(Base64.encodeBase64(mac.doFinal(text))).trim();
}
我错过了什么吗?如何解决此错误?
解决方案
推荐阅读
- tensorflow - 无法在 google colab 中加载图像以进行对象识别
- android - 如何解决 INSTALL_FAILED_MISSING_SHARED_LIBRARY 以运行 Android Things 应用程序开箱即用?
- sql-server - 改善可怕的 MERGE 性能
- regex - 如何在 RegEx 中对字符串的同一部分使用多个前瞻?
- javascript - 如何从Angular ngFor中的方法中提取值
- java - 是否可以强制 java.sql.Date 仅将年、月、日插入 Oracle 日期列
- ruby-on-rails - ActiveJob + Sidekiq 6.0.3:如何写入日志文件?
- android - 无法安装 Intel x86 Emulator Accelerator(HAXM 安装程序)
- python-3.x - 从python中的列表计算最大时间差
- python - 如何为 DRF 中的方法设置不同的权限类