2014-09-19 4 views
0

2 개의 사이트가 있습니다.GF WebAPI를 사용하여 외부 사이트에서 새로운 Gravity Forms 항목을 만듭니다.

  • Sita A는 Wordpress를 실행하며 중력 양식이 있습니다.
  • 사이트 B는

에 관계없이 내가하려고 어떤 사이트 A에 중력 양식에 항목을 추가 할 Gravity Forms Web API을 사용하려고, 내가 할 수있는 최선의 결과가 "창조 자원이"응답 (201)와 빈 응답 객체. 성공 응답에 관계없이 레코드가 생성되지 않습니다.

{"status":201,"response":[]} 

데이터를 가져 와서 인증 문제가 아닌 것 같습니다. 설명서에는 응답에 "결과를 설명하는 현지화 된 메시지 :"항목이 성공적으로 생성되었습니다 "라는 내용이 포함되어 있습니다.

나는 /항목뿐만 아니라 /양식/$ form_id/항목

나는 웹 API 클라이언트 플러그인을 설치하고 성공적으로 기록을 만들어 가리키는 시도했습니다. 나는 또한 그 코드를 천 번 쏟아 부었다. 그 플러그 uses wp_remote_request 내가 Wordpress를 실행하지 않기 때문에 사용할 수없는 데이터를 게시 할 수 있습니다.

<?php 
$api_key = '123'; 
$private_key = 'abc'; 
$method = 'POST'; 
$endpoint = 'http://example.com/gravityformsapi/'; 
$route = 'entries'; 
//$route = 'forms/17/entries'; 
$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; 

$data = array(
    "id" => "", 
    "date_created" => "", 
    "form_id" => "17", 
    "1" => "[email protected]" 
); 

$ch = curl_init($api_call); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POST, 1); 

$result = curl_exec($ch); 

print_r($result); 

답변

1

귀하의 코드가 가까이 :

여기에 현재 코드입니다. http_build_query 대신 json_encode을 사용했습니다.

고아가 된 항목에 대해 리드 테이블을 확인하고자 할 수 있습니다.

<?php 
$api_key = 'keyhere'; 
$private_key = 'privatekey'; 
$method = 'POST'; 
$endpoint = 'https://www.site.com/gravityformsapi/'; 
//$route = 'entries'; 
$route = 'forms/1/entries'; 
$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"=>"firstname","1.6"=>"lastname","2"=>"","3"=>"[email protected]","4"=>"testtest","5"=>"something else") 
); 

$ch = curl_init($api_call); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($entries)); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POST, 1); 

$result = curl_exec($ch); 

print_r($result);//201 status indicates it inserted the entry. Should return id of the entry. 

function calculate_signature($string, $private_key) { 
    $hash = hash_hmac("sha1", $string, $private_key, true); 
    $sig = rawurlencode(base64_encode($hash)); 
    return $sig; 
} 
?> 
: 여기

나를 위해 노력하고 몇 가지 코드