I am calling an api with OAuth 1.0 and i am using the below package for the api call. But I am getting the below error. Please anyone guide me to fix this error.
Library for api call:
My Code:
const String apiKey = 'ck_789b63aee985c4569bfa5ae4724861ae5c74c337';
const String apiSecret = 'cs_0f0addbc9c16042d5689a4cfe6fbfd209b00d55b';
var clientCredentials = new oauth1.ClientCredentials(Uri.encodeComponent(apiKey), Uri.encodeComponent(apiSecret));
// create Authorization object with client credentials and platform definition
//var auth = new oauth1.Authorization(clientCredentials, platform);
var auth = new oauth1.Credentials(apiKey, apiSecret);
// yeah, you got token credentials
// create Client object
var client = new oauth1.Client(platform.signatureMethod, clientCredentials, auth);
// now you can access to protected resources via client
client.get('http://demo2.signitydemo.in/foodemporium/wp-json/wc/v3/products/categories').then((res) {
print("res.body===${res.body}");
print("statusCode===${res.statusCode}");
print("headers===${res.headers}");
});
{"code":"woocommerce_rest_authentication_error","message":"Invalid signature - provided signature does not match.","data":{"status":401}}
Headers:
{link: <http://demo2.signitydemo.in/foodemporium/wp-json/>; rel="https://api.w.org/", access-control-allow-headers: Authorization, Content-Type, connection: keep-alive, date: Fri, 03 Jul 2020 05:32:04 GMT, transfer-encoding: chunked, vary: Origin, access-control-expose-headers: X-WP-Total, X-WP-TotalPages, x-robots-tag: noindex, content-type: application/json; charset=UTF-8, x-content-type-options: nosniff, server: nginx}
I have tested the API in Postman. It is working fine, I am getting the response. Please see the below postman API request.