CI 묻고 답하기

제목 페이스북 사진 올리기. cURL POST 전송
글쓴이 Lectom 작성시각 2012/02/21 14:47:25
댓글 : 3 추천 : 0 스크랩 : 0 조회수 : 28064   RSS
 
 벌써 일주일 가까이... 낑낑거렸지만 해결이 안 되어서 올립니다.. ㅠ.ㅠ

 순전히 CI 질문은 아니구요... 양해 부탁드릴께요... 답답해서;;;

 
 페이스북 토큰은 정상적으로 가져온 상태이구..

 
$this->curl->simple_post("https://graph.facebook.com/me/feed",
             array('access_token'=>$fb_token, 
                   'comment'=>$comment, 
                   'picture'=>$domain.'/img/for_test.jpg'));  

 정상적으로 담벼락에 잘~ 개시됩니다.. 현제 이 코드로 페이스북 어플도 개발한 상태이구요...

 문제는,,

 
$this->curl->simple_post("https://graph.facebook.com/me/photos",
             array('access_token'=>$fb_token,
                   'message'=>$comment, 
                   'source'=>'@'.realpath('/img/for_test.jpg')));

 에서는 아무 반응을 안 하네요  ㅠ.ㅠ// 혹시나 해서 폼 구문으로 직접 데이터를 전송해 보니 잘 올라갑니다. (페이스북 제시 예시)
          
         $graph_url= "https://graph.facebook.com/me/photos?"
         . "access_token=" .$fb_token;
echo '<html><body>'; echo '<form enctype="multipart/form-data" action="' .$graph_url .' "method="POST">'; echo 'Please choose a photo: '; echo '<input name="source" type="file"><br/><br/>'; echo 'Say something about this photo: '; echo '<input name="message" type="text" value=""><br/><br/>'; echo '<input type="submit" value="Upload"/><br/>'; echo '</form>'; echo '</body></html>';

 결론! 폼구문 전송과 같은 형태의 파일을 cURL POST로 보내고 싶어요. 어느 부분을 고쳐야 할까요...? -.-?


 다음글 서브도메인을 파라미터로 넘기기 (7)
 이전글 utf-8 환경에서 euc-kr로 인코딩된 url을 받... (2)

댓글

변종원(웅파) / 2012/02/21 15:42:38 / 추천 0
파이어버그에서 보면 어떤 식이던지 로그나 에러메시지가 나올텐데요? Ci로그도 보시구요
Lectom / 2012/02/21 17:39:25 / 추천 0
 파이어 버그도 꺠끗. CI 로그도 깨끗.
 결국 cURL 에러를 찾아보았더니, 
  cURL error:failed creating formpost data 라고 뜨네요... 왜 데이터를 못 만든다는 걸까요..

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/me/photos");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_POST, 1);
     
$post = array(
               'access_token' => $fb_token,
               'message'=>$comment,
               'image'=>'@'.'home/triso/public_html/img/for_test.jpg'
     );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
$response = curl_exec($ch);
$sHttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
print "<pre>\n";
print_r(curl_getinfo($ch));  // get error info
echo "\n\ncURL error number:" .curl_errno($ch); // print error info
echo "\n\ncURL error:" . curl_error($ch); 
print "</pre>\n";

Lectom / 2012/02/21 18:01:38 / 추천 0
 일단, 올라는 갑니다... 

 윗 댓글에서 나왔던
 'image'=>'@'.'/home/triso/public_html/img/for_test.jpg'

 부분이 잘못되었던건데... 문제는 -.-... cURL 라이브러리를 사용했을 경우는 여전히 안되네요..

 왜 파일전송은 안되는건지 모르겠지만. 함수로 만들어서 써야겠어요.... 감사합니다 (꾸벅)