【问题标题】:woocommerce_rest_cannot_view with oauth 1.0woocommerce_rest_cannot_view 与 oauth 1.0
【发布时间】: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


    【解决方案1】:

    不确定,但我认为问题来自 https://github.com/WP-API/OAuth1 因为在我删除它之后 问题解决了

    显然,当我尝试使用 HTTP Woocommerce Rest API OAuth1 插件之间存在冲突 和 Woocommerce Rest API

    但我的问题没有解决 有另一个 OAuth 插件 WordPress 来验证应用程序并使其可以查看所有 WordPress REST API 源?

    谢谢

    【讨论】:

      猜你喜欢
      • 2019-02-05
      • 2015-05-11
      • 1970-01-01
      • 2017-06-30
      • 1970-01-01
      • 2018-04-12
      • 2015-07-01
      • 2014-10-14
      • 1970-01-01
      相关资源
      最近更新 更多