0
我正嘗試使用Gravity Forms Web API來更新條目,這是我目前使用的PHP代碼。Gravity Forms Web API更新條目
<?php
$api_key = '';
$private_key = '';
$method = 'PUT';
$endpoint = 'https://www.website.co.uk/gravityformsapi/';
//$route = 'entries';
$route = 'entries/61';
$expires = strtotime('+60 mins');
$string_to_sign = sprintf('%s:%s:%s:%s', $api_key, $method, $route, $expires);
$sig = calculate_signature($string_to_sign, $private_key);
$api_call = $endpoint.$route.'?api_key='.$api_key.'&signature='.$sig.'&expires='.$expires;
//array of entries (each entry is an array with key=field id)
$entries = array(
array("status"=>"active","1.3"=>$_POST['first_name'],)
);
$ch = curl_init($api_call);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($entries));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
function calculate_signature($string, $private_key) {
$hash = hash_hmac("sha1", $string, $private_key, true);
$sig = rawurlencode(base64_encode($hash));
return $sig;
};
?>
我得到的迴應是成功更新了帖子,但是不是更新帖子,而是似乎刪除帖子。任何人都可以看到我的代碼有什麼問題?如果我刷新我在Wordpress上編輯的條目的頁面,則會出現此錯誤。
Fatal error: Cannot use object of type WP_Error as array in /data02/c6536622/public_html/wp-content/plugins/gravityforms/entry_detail.php on line 57
反正是有得到一個日誌,找出什麼錯誤使用重力形式,或WordPress的?