2013-03-05 8 views
2

Badgeville REST API를 curl 7.22 응용 프로그램과 통합하고 있습니다.PHP Curl 대 커맨드 라인 컬의 차이점

BV의 API 설명서는 해당 예제에 대한 명령 줄 컬 호출을 사용합니다. 이 예제를 실행할 때 제대로 작동합니다.

PHP Curl 클래스에서 동일한 작업을 시도 할 때 항상 BV 서버에서 500 오류가 발생합니다.

Chrome의 고급 휴식 클라이언트 확장 프로그램과 함께 synonomous 기능을 수행하려고했습니다.

PHP 컬 예 :

$ch = curl_init('http://sandbox.v2.badgeville.com/api/berlin/[private_api_key]/users.json'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); 

if($this->getRequestType() == 'POST') 
{ 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, 
     array(
      'user[name]' => 'Generic+Username', 
      'user[email]' => 'johndoe%40domainname.com' 
     ); 
    ); 
} 

$response = curl_exec($ch); 

나머지 클라이언트 예 :

URL : http://sandbox.v2.badgeville.com/api/berlin/[private_api_key]/users. JSON

POST 페이로드에 헤더 :

사용자 [이름] = + 일반 자명 0,123,224 9,사용자 [메일] = JohnDoe에 % 40domainname.com

내가 수동으로 명령 줄 컬 호출을 생성하고 shell_exec()과 실행,하지만 난 정말 그렇게 할 필요가없는 것을 선호했다.

내 연구에서는 Drupal module을 발견했으며 모든 API 호출은 fsockopen() 호출을 통해 수행됩니다.

PHP Curl 클래스를 사용하여 Badgeville 호출을 성공적으로 수행하는 방법이 있습니까?

답변

1

머리말이 설정된 컬 요청이 들어 오면 Badgeville은 500 오류가 발생합니다.

오류 반환 코드 :

$ch = curl_init('http://sandbox.v2.badgeville.com/api/berlin/[private_api_key]/users.json'); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); 

if($this->getRequestType() == 'POST') 
{ 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, 
     array(
      'user[name]' => 'Generic+Username', 
      'user[email]' => 'johndoe%40domainname.com' 
     ); 
    ); 
} 

$response = curl_exec($ch); 

제대로 작동 코드 :

$ch = curl_init('http://sandbox.v2.badgeville.com/api/berlin/[private_api_key]/users.json'); 
//curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); 

if($this->getRequestType() == 'POST') 
{ 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, 
     array(
      'user[name]' => 'Generic+Username', 
      'user[email]' => 'johndoe%40domainname.com' 
     ); 
    ); 
} 

$response = curl_exec($ch); 

SMH