request using HTTP Outh 2 authentication with PHP curl not work?


request using HTTP Outh 2 authentication with PHP curl not work?



I have set up a http request using PHP CURL with following code.


PHP CURL


<?php

$para='{
"payment_method": "bacs",
"payment_method_title": "Direct Bank Transfer",
"set_paid": true,
"billing": {
"first_name": "John",
"last_name": "Doe",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US",
"email": "john.doe@example.com",
"phone": "(555) 555-5555"
},
"shipping": {
"first_name": "John",
"last_name": "Doe",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US"
},
"line_items": [
{
"product_id": 13,
"quantity": 2
}

]

}';

$process= curl_init('http://xxx');
$header = 'Content-Type: application/json';
curl_setopt($process, CURLOPT_HEADER, $header);
curl_setopt($process, CURLOPT_POST, true);
curl_setopt($process, CURLOPT_POSTFIELDS, urlencode("oauth_consumer_key=xxxxxxfa18148227334d91&
oauth_signature_method=HMAC-SHA1&
oauth_signature=xxxxx%253D&
oauth_timestamp=xxxx&
oauth_nonce=xxXbG&
oauth_version=2.0"));
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_POSTFIELDS, $para);
$return = curl_exec($process);
print_r($return);
curl_close($process);
?>



It's given following error i want to get woocommerce order api using curl this is woocommerce rest api related i have also add this RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] in .htaccess but still is not work.


RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]


{"code":"woocommerce_rest_cannot_create","message":"Sorry, you are not allowed to create resources.","data":{"status":401}}



Someone please help me how do i resolve this ?





Where is the $process variable coming from? As the error says, it is null. Please post your full code.
– Kovah
Jun 29 at 11:02


$process


null





The error is clear - The $process which you pass as the first parameter to a call to curl_setopt() is null. Nothing at all to do with OAuth as you mentioned in the title. In your code $process is the result of a call to curl_init()...now go and read: php.net/manual/en/function.curl-init.php . It says "Returns a cURL handle on success, FALSE on errors.". So really it should return something. How it comes to be null is a mystery, based on your code. However you might at least double-check your code to see whether the call to curl_init() succeeded or not.
– ADyson
Jun 29 at 11:14



$process


$process


curl_init()









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

how to run turtle graphics in Colaboratory

Export result set on Dbeaver to CSV