티스토리에 글을 좀 편하게 자동으로 쓰려고 시도하다가
글 작성은 다 되는데 이미지 파일 첨부까지 해보려는데 쉽지 않네요.
일단 제가 사용한 소스에
public function post_attach ($parameters) {
$data = array();
$parameters[CURLOPT_HTTPHEADER] = array('Content-Type'=>'multipart/form-data');
$parameters[CURLOPT_POST] = true;
// set access_token
if (isset($this->access_token)) {
$data['access_token'] = $this->access_token;
$data['output'] = 'json';
}
if (is_file($parameters['uploadedfile'])) {
$mime_type = mime_content_type($parameters['uploadedfile']);
$cf = curl_file_create($parameters['uploadedfile'],$mime_type,pathinfo($parameters['uploadedfile'],PATHINFO_BASENAME));
$data['uploadedfile'] = $cf;
}
$data['blogName'] = $parameters['blogName'];
unset($parameters['blogName']);
unset($parameters['uploadedfile']);
$parameters[CURLOPT_POSTFIELDS] = $data;
$response = $this->get_content_curl($this->api_url.'apis/post/attach',$parameters);
$data = array();
if ($response['response']['http_code'] == 200) {
$data = $response['html'];
}
return $data;
}
위와 같은 함수 제공하고 있습니다.
* 파일 첨부 API
* http://www.tistory.com/guide/api/post#post-attach
*
* @param array $parameters
* string $parameters['blogName'] xxx.tistory.com 의 xxx
* string $parameters['uploadedfile'] multipart file data
*
* @return array $data
*/
위와 같이 사용해야 하구요.
api 메뉴얼
------------------------------------------
https://tistory.github.io/document-tistory-apis/apis/v1/post/attach.html
POST https://www.tistory.com/apis/post/attach? access_token={access-token} &blogName={blog-name} [uploadedfile]
기본 매개변수를 제외한 매개변수는 다음과 같습니다.
blogName: Blog Name 입니다.
uploadedfile: 업로드할 파일 (multipart/form-data)
---------------------------------
제가 사용하려는 이미지가 외부의 이미지입니다.
$productImage ='url';
$parameters = array();
$parameters['blogName'] = 'https://***.tistory.com/';
$parameters['uploadedfile'] = $productImage;
$tistory_api->set_api(array('access_token'=>$_SESSION['access_token']));
$data = $tistory_api->post_attach($parameters);
저 굵은 색 부분이 저희 서버쪽으로 가져와서 뭔가 형태를 바꿔줘야 할 것 같은데 단서를 못찾겠네요.
저희 서버에 임시 파일 형태로 가동된 결과물이 $parameters['uploadedfile'] 에 담기도록 해야 할 것 같다는 것 까지만 추측하고 있습니다.
$parameters['blogName'] = 'https://***.tistory.com/';
https://tistory.github.io/document-tistory-apis/GLOSSARY.html#blog-name
"블로그를 구분하는 식별자로 사용되며 티스토리 주소 xxx.tistory.com에서 xxx를 나타냅니다."
라고 되어 있는데 이부분도 확인해 보셨나요? *** 부분만 적으셔야 할것 같은데요.
=====
API 문서를 보면 access_token과 blogName은 GET 파라메터로, 나머지 실제 업로드할 파일은 multipart/form-data 형태로 POST 본문에 첨부해야 하는것 같습니다.