【发布时间】:2021-06-02 21:00:40
【问题描述】:
我使用 OAuth 1.0a 以管理员身份验证我的 android 应用程序以查看 Woocommercerest API 源 我使用改造库,它可以工作,但今天我遇到了这个问题
I/okhttp.OkHttpClient: Content-Type: application/json;字符集=UTF-8 {"code":"woocommerce_rest_cannot_view","message":"抱歉,您不能列出资源。","data":{"status":401}}
我在 localhost 和我的真实站点上尝试过,但仍然是同样的问题 我尝试使用 HTTP 和 HTTPS,并将 useClearTextTrafix 添加到 true 并且仍然是同样的问题 我尝试通过 HTTP 和 HTTPS 使用 Woocommerce REST API 身份验证 还是一样的问题
我的 apiClient
if (retrofit == null) {
OAuthInterceptor oauth1WooCommerce = new OAuthInterceptor.Builder()
.consumerKey(CONSUMER_KEY)
.consumerSecret(CONSUMER_SECRET)
.token(TOKEN)
.tokenSecret(TOKEN_SECRET)
.isShouldExcludeOAuthToken(false)
.build();
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder builder = new OkHttpClient().newBuilder().connectTimeout(3, TimeUnit.MINUTES).readTimeout(3, TimeUnit.MINUTES);
builder.addInterceptor(interceptor);
if (isShouldAddOauth1) {
builder.addInterceptor(oauth1WooCommerce);
}
retrofit = new Retrofit.Builder()
.baseUrl(Constants.BASE_URL)
.client(builder.build())
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit.create(ApiInterface.class);
我在 StackOverflow 中看到了所有问题,但没有找到答案 它适用于邮递员,但有时我会收到此错误
{
"code": "json_oauth1_signature_mismatch",
"message": "OAuth signature does not match",
"data": {
"status": 401
}
}
请帮忙,谢谢
【问题讨论】:
标签: android-studio woocommerce wordpress-rest-api woocommerce-rest-api oauth-1.0a