我正在尝试从iOS创建一个订单,以使用Alamofire吸引商业。我正在寻找一个合适的解决方案。
尝试创建订单后,出现此错误:
{
code = "woocommerce_rest_cannot_create";
data = {
status = 401;
};
message = "Sorry, you are not allowed to create resources.";
}
法典:
let parameters: [String: AnyObject] = [
"consumer_key":"*******" as AnyObject, // here is my user name
"consumer_secret":"*******" as AnyObject, // here is my secret key
"shipping_total": "120.00" as AnyObject,
"total": "6015.00" as AnyObject,
"customer_id": 0 as AnyObject,
"billing": [
"first_name": "Faizul",
"last_name": "karim",
"company": "somecompany",
"address_1": "someAddress",
"address_2": "someAddress",
"city": "Dhaka",
"state": "Dhaka",
"postcode": "1203",
"country": "bd",
"email": "faizulkarim28@gmail.com",
"phone": "001929838939"
] as AnyObject,
"shipping": [
"first_name": "Faizul",
"last_name": "karim",
"company": "somecompany",
"address_1": "someAddress",
"address_2": "someAddress",
"city": "Dhaka",
"state": "Dhaka",
"postcode": "1203",
"country": "bd",
] as AnyObject,
"line_items":[
"id": 388,
"name": "Mens Casual Blazer - 40",
"product_id": 55677,
"variation_id": 57619,
"quantity": 1,
"tax_class": "",
"subtotal": "5895.00",
"subtotal_tax": "0.00",
"total": "5895.00",
"total_tax": "0.00",
] as AnyObject
]
Alamofire.request("https://infinitymegamall.com/wp-json/wc/v2/orders",method: .post, parameters: parameters)
.responseJSON{ response in
if let json = response.result.value {
print(json)
}
}
您确定您的 API 密钥具有写入权限吗?如果 GET 有效,则密钥可能允许只读。仔细检查您的WoocommerceAPI设置中的权限。