티스토리 Open API 클라이언트 등록하기

티스토리 Open API 기능이 좀 복잡 해졌다 직관적으로 이해가 가지 않는다 .
차후에 사용하게 되겠지만 먼저 요약해서 정리 해놓자 Open APi 가이드 에서 뭐라뭐라 설명 해놓긴 했는데 이해가 가지 않는다.
티스토리 API 중 글수정 API 를 이용하면 쉽게 가능합니다.
다른 언어도 많겠지만, 저는 PHP 가 간편하여, PHP 로 하는것을 설명드립니다.
전제조건 1. 도메인이나 웹호스팅 계정이 있어야 한다.
전제조건 2. curl (Client URL Library) 를 사용가능해야 한다.
전제조건 3. PHP 를 할줄 알아야 한다. -_-v..
위 전제조건에 해당되지 않는 분들을 위해서 공개 페이지도 제공해드립니다.
단, 해당 서비스를 사용함에 따른 불이익은 본인이 감수하셔야 합니다.
그럴일은 없겠지만, 재수없게 포스팅한 내용이 사라진다던가 -_-….
아래 주소를 클릭하시면 해당 서비스를 이용가능합니다.
http://tistory.i-swear.com

 
 
 
 
 

1. 티스토리 오픈 API 에서 Consumer 로 등록

티스토리에 로그인하여 Consumer 등록페이지로 이동합니다.
티스토리는 OAuth1 을 사용합니다.

서비스명과 설명은 대충 넣습니다.
서비스 URL 은 현재 코딩한 후 업로드할 서버 URL 을 입력합니다.
예) http://tistory.i-swear.com
CallBack 경로는 티스토리 인증창이 뜬후 돌아갈 경로를 입력합니다.
해당 경로로 Access Token 이 발급됩니다. 반드시 유효한 경로를 입력하셔야 합니다.
예) http://tistory.i-swear.com/callbak.php
OAuth 약관에 동의한후 등록을 하시면, Consumer 관리 페이지에서 내가 등록한 내역을 확인할 수 있습니다.
이곳은 꼭 확인하셔야 합니다.
왜냐하믄, 이곳에 가장 중요한 client_id 와 secret_key 가 있습니다.


상세보기를 클릭하시면 아래 이미지처럼 나옵니다.

그럼 이제, 티스토리 관리 페이지는 볼 필요가 없습니다.
Client ID, Secret Key, CallBack 경로는 앞으로 코딩할 곳에 쓰이니 다른 곳에 복사해 둡시다.

티스토리 오픈API 로 Access Token 을 받자.

1부에서 OAuth 흐름에 대해서 언급하지 못하고 지나갔었는데요.대략 흐름은 아래와 같습니다.1. 블로거가 Consumer 로 등록된 사이트에 접속
예) http://tistory.i-swear.com
2. Access Token 을 받기 위해서 티스토리로 페이지 이동
이때 로그인이 되어있지 않다면 로그인 창이 뜹니다.
3. 블로거가 TISTORY OAUTH 창으로 접속됩니다. 아래 이미지 참조.

이곳에서 허가하기를 누르면 Access Token 이 발급되어 Consumer 에서 등록한 권한 (읽기, 읽기/쓰기) 를 가지게 됩니다.
물론 취소를 누른다면 창은 닫히게 되고요. ^^.
이 Access Token 을 가지고 허용된 API (글정보,글수정,글삭제,글등록 등등) 을 사용할수 있게 됩니다.
대충 설명은 이렇게 하고요.
그럼 이제, 코딩 시작…..
아주 심플하게 코딩만 할것이기 때문에 크래킹이나 XSS 에 대해서 고려하지 않음을 알려드립니다.

티스토리 오픈API 로 Access Token 을 받자.

1부에서 Client Id , Secret Key 를 발급받았습니다.
그럼 얘들을 어디에 쓰느냐…
내가 이런 저런 서비스를 하기 위한 고유의 키(?)라고 생각하시면 됩니다.

일일이 복사하기 귀찮은 분들위한 다운로드 서비스.
 config.php
 step1.php
 callback.php
config.php 파일을 만들자.
config.php 에는 Client ID 와 Secret Key 를 저장해 둡시다.

### php
config.php
$_client_id    = “티스토리에서 발급받은 Client ID 를 입력”;
$_secret_key   = “티스토리에서 발급받은 Secret Key 를 입력”;
$_callback_url = “http://티스토리 Consumer 에 입력한 CallBack 경로”;

토대로 step1.php 파일을 만듭니다.
이 파일의 역할은 티스토리에 로그인 한 사용자에게서 Access Token 을 받기 위해 티스토리로 Redirect 해주는 파일입니다.

### php
step1.php
include “config.php”;
$url  = “https://www.tistory.com/oauth/authorize/”;
$url .= “?client_id={$_client_id}”;
$url .= “&redirect_uri={$_callback_url}”;
$url .= “&response_type=code”;
header(“Location: {$url}”);

이제 callback.php 파일을 만듭니다.
이 파일의 역할은 티스토리에서 TISTORY OAUTH 을 허가한 사용자의 code 을 넘겨줍니다.
step2.php 로 해야되는데, CallBack 부분이기 때문에 callback.php 로 하겠습니다.
GET 변수로 code 가 넘어오므로, 이 값을 가지고 Access Token 을 받아야 합니다.

### php
callback.php
include “config.php”;
$url = “https://www.tistory.com/oauth/access_token/?”;
$url .= “&client_id={$_client_id}”;
$url .= “&client_secret={$_secret_key}”;
$url .= “&redirect_uri=” . urlencode($_callback_url);
$url .= “&code={$_GET[‘code’]}”;
$url .= “&grant_type=authorization_code”;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_HEADER, false);
$content = curl_exec($ch);
curl_close ($ch);
$content = str_replace(‘access_token=’, ”, $content);
$_SESSION[‘access_token’] = $content;

이제 access token 을 받았으니, 글읽기와 글수정에 대해서 알아보겠습니다.

Access Token 으로 글을 수정하자

하루가 지나서야 3부를 작성하네요…
월초라서 회사일이 바쁘다보니 ^^… 더군다나 오늘은 우리 아기의 선물을 택배아저씨가 으쌰으쌰 들고 오셔서 그걸 조립하느라 3시간을 허비했네요.
그럼, 이제 3부를 가볼까요.
아마 3부가 마지막이 될거 같습니다. ㅎㅎ
티스토리에서 모바일 애드센스를 붙이기 위한 우리에게 가장 필요한건 뭐?
그렇죠. ㅎㅎ 본문 상단에 광고코드만 딱!!!!하니 들어가면 된다 이거죠.
Access Token 으로 글을 수정하자
2부에서 받아온 Access Token 을 세션변수에 딱하니 저장해두었습니다.
그럼, 이 세션변수로 블로그 정보를 읽어야 되는데, 그러기엔 귀찮습니다.
해당하는 글만 수정하는 방향으로 코드를 짜는겁니다.
파일이름은 step2.php 로 지정하겠습니다.
그전에 내가 수정할 글 번호를 알아야 합니다. 그럼, 그 글번호는 어떻게 아느냐…
지금 현재 이 글의 주소를 보시면 http://www.i-swear.com/882 라고 되어있을겁니다.
이 882 라는 주소가 글번호입니다.
이번파일도 복사하기 귀찮은 분들을 위해 다운로드는 서비스!
step2.php
### php
include “config.php”;
$_SESSION[‘access_token’] = trim($_SESSION[‘access_token’]);
// 글내용을 가져옵니다.
// 나의 블로그 주소는 2차 도메인이 http://i-swear.com 이라면
// i-swear.com 을 기록하고,
// 2차도메인이 없이 티스토리 도메인을 사용한다면 (티스토리아아디.tistory.com)
// 티스토리아이디만 입력합니다.
$url = “https://www.tistory.com/apis/post/read”;
$url .= “?access_token={$_SESSION[‘access_token’]}”;
$url .= “&targetUrl=나의블로그주소&postId=글번호”;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_HEADER, false);
$content = curl_exec( $ch );
curl_close ( $ch );
$xmlObj = simplexml_load_string($content);
$row = $xmlObj2->item;
// 글수정하기
$title = urlencode($row->title);
$content = “구글광고코드입력”;
$content .= $row->content; // 글본문
$content = urlencode($content);
$POST_DATA = “access_token={$_SERVER[‘access_token’]}”;
$POST_DATA .= “&targetUrl=나의블로그주소”;
$POST_DATA .= “&title={$title}”;
$POST_DATA .= “&postId={$row->id}”;
$POST_DATA .= “&content={$content}”;
$url = “https://www.tistory.com/apis/post/modify”;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_HEADER, false);
curl_setopt ($ch, CURLOPT_POST ,1);
curl_setopt ($ch, CURLOPT_POSTFIELDS , $POST_DATA);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec( $ch );
curl_close ( $ch );
이렇게 하는 것으로 간단하게 티스토리 API 를 이용하여 글을 수정할수 있었습니다.
무언가 부족한것 같지만, 여기서 마무리를 지을까합니다.
광고 삽입 쉽게 하기 링크를 따라가시면 아래와 같은 페이지를 보실수 있습니다.
부족한 설명을 이걸로 떼우겠습니다. -ㅅ-

 
 
 
API 사용소스 참조 
http://zetawiki.com/wiki/티스토리글쓰기_API
http://www.tistory.com/guide/api/index
티스토리에 API로 글 올리기 할 경우 이미지 첨부 안됨

“티스토리 Open API 클라이언트 등록하기”의 79개의 댓글

  1. 핑백: viagra pills

  2. I simply want to tell you that I am all new to blogging and actually liked your web site. Likely I’m want to bookmark your site . You surely have wonderful articles. Thank you for revealing your website.

  3. When I initially commented I clicked the -Inform me when brand-new comments are included- checkbox as well as now each time a remark is added I obtain 4 e-mails with the very same comment. Is there any way you can remove me from that solution? Many thanks!

  4. This design is wicked! You obviously know how to keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Great job. I really enjoyed what you had to say, and more than that, how you presented it. Too cool!

  5. The next time I read a blog, I hope that it doesn’t disappoint me as high as this set. I indicate, I understand it was my choice to review, yet I actually believed youd have something fascinating to claim. All I hear is a number of yawping regarding something that you could repair if you werent as well busy searching for attention.

  6. Can I just state what a relief to discover somebody who really recognizes what theyre speaking about on the internet. You most definitely know just how to bring a problem to light and make it essential. More people require to read this and also recognize this side of the tale. I cant think youre not a lot more popular because you absolutely have the gift.

  7. I was extremely happy to locate this web-site. I intended to many thanks for your time for this wonderful read!! I definitely taking pleasure in every bit of it and I have you bookmarked to look into new things you article.

  8. I was really happy to find this web-site. I intended to thanks for your time for this wonderful read!! I most definitely appreciating every little bit of it and I have you bookmarked to take a look at brand-new things you post.

  9. I am commonly to blog writing and i really appreciate your web content. The short article has truly peaks my rate of interest. I am going to bookmark your site as well as maintain looking for new information.

  10. The following time I read a blog, I really hope that it does not dissatisfy me as much as this set. I indicate, I understand it was my selection to review, yet I actually believed youd have something fascinating to say. All I listen to is a number of yawping regarding something that you could fix if you werent too active seeking interest.

  11. An outstanding share, I just given this onto an associate who was doing a little analysis on this. And also he actually acquired me morning meal because I found it for him. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for investing the time to discuss this, I really feel highly about it as well as love reading more on this subject. Preferably, as you end up being proficiency, would certainly you mind updating your blog with more details? It is highly useful for me. Large thumb up for this blog post!

  12. This is the ideal blog for anybody that wishes to discover this subject. You recognize a lot its nearly hard to say with you (not that I actually would want?HaHa). You absolutely put a brand-new spin on a topic thats been covered for several years. Great things, just fantastic!

  13. There are some intriguing points in time in this short article however I don?t recognize if I see all of them center to heart. There is some legitimacy however I will certainly hold viewpoint up until I check into it further. Good post, many thanks as well as we want extra! Added to FeedBurner too

  14. Oh my goodness! an outstanding article guy. Thank you Nevertheless I am experiencing issue with ur rss. Don?t understand why Not able to subscribe to it. Is there any person getting the same rss problem? Any individual that recognizes kindly react. Thnkx

  15. An outstanding share, I just provided this onto an associate that was doing a little evaluation on this. And also he in fact got me morning meal since I located it for him. smile. So let me reword that: Thnx for the treat! Yet yeah Thnkx for investing the time to review this, I feel highly regarding it and also love learning more on this subject. Ideally, as you end up being expertise, would you mind upgrading your blog site with more information? It is very valuable for me. Huge thumb up for this post!

  16. I just want to mention I’m new to blogs and actually enjoyed this website. Likely I’m want to bookmark your blog . You actually come with good well written articles. Thanks a bunch for sharing your web-site.

  17. Hi there, I found your web site by the use of Google whilst searching for a comparable subject, your web site came up, it appears to be like good. I’ve bookmarked it in my google bookmarks.

  18. Magnificent goods from you, man. I have understand your stuff previous to and you’re just extremely magnificent. I really like what you have acquired here, certainly like what you are saying and the way in which you say it. You make it enjoyable and you still care for to keep it wise. I cant wait to read much more from you. This is actually a great site.

  19. Does your site have a contact page? I’m having trouble locating it but, I’d like to send you an email. I’ve got some recommendations for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it grow over time.

  20. I have been exploring for a bit for any high quality articles or blog posts on this sort of area . Exploring in Yahoo I at last stumbled upon this website. Reading this info So i’m happy to convey that I have an incredibly good uncanny feeling I discovered exactly what I needed. I most certainly will make certain to don’t forget this web site and give it a look on a constant basis.

  21. Thanks for the tips shared on your blog. Something also important I would like to talk about is that weight reduction is not exactly about going on a dietary fads and trying to shed as much weight as you’re able in a few months. The most effective way to shed weight is by getting it bit by bit and obeying some basic guidelines which can assist you to make the most from a attempt to shed weight. You may recognize and be following a few of these tips, but reinforcing information never hurts.

  22. I was just looking for this information for some time. After six hours of continuous Googleing, finally I got it in your web site. I wonder what is the lack of Google strategy that don’t rank this type of informative sites in top of the list. Usually the top sites are full of garbage.

  23. Hi, I think your blog might be having browser compatibility issues. When I look at your blog in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, wonderful blog!

  24. I’ve been browsing online more than three hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. In my opinion, if all web owners and bloggers made good content as you did, the internet will be a lot more useful than ever before.

  25. Iím impressed, I have to admit. Seldom do I come across a blog thatís both equally educative and interesting, and let me tell you, you have hit the nail on the head. The problem is something too few people are speaking intelligently about. Now i’m very happy I came across this in my search for something regarding this.

  26. I simply want to say I am just new to blogs and actually loved this website. Most likely I’m want to bookmark your blog . You amazingly come with very good well written articles. Many thanks for sharing your web-site.

  27. This website post is excellent, probably because of how well the subject was developped. I like some of the comments too though I would prefer we all stay on the suject in order add value to the subject!

  28. I¡¦m not certain the place you’re getting your info, however great topic. I needs to spend a while studying much more or understanding more. Thank you for magnificent info I used to be in search of this information for my mission.

  29. Excellent goods from you, man. I have remember your stuff prior to and you’re just extremely great. I actually like what you’ve obtained here, certainly like what you’re saying and the way in which wherein you assert it. You are making it entertaining and you still care for to stay it wise. I can’t wait to learn far more from you. That is really a wonderful web site.

  30. Hi there! This is my 1st comment here so I just wanted to give a quick shout out and say I genuinely enjoy reading your posts. Can you suggest any other blogs/websites/forums that go over the same topics? Thanks a lot!

  31. An impressive share, I simply given this onto a colleague who has been performing a little analysis with this. And the man actually bought me breakfast because I uncovered it for him.. smile. So let me reword that: Thnx to the treat! But yeah Thnkx for spending some time go over this, I’m strongly about it and really like reading on this topic. Whenever possible, as you become expertise, might you mind updating your blog post with additional details? It can be extremely helpful for me. Massive thumb up just for this post!

  32. Good article in addition to simple to help understand explanation. How do When i try obtaining permission to help publish part on the article around my approaching e-newsletter? Giving correct credit ratings to your account this author in addition to link towards webpage would not become a dilemma.

  33. The very next time I read a blog, Hopefully it doesn’t disappoint me as much as this one. I mean, Yes, it was my choice to read through, nonetheless I really believed you would have something helpful to talk about. All I hear is a bunch of crying about something that you could possibly fix if you were not too busy seeking attention.

  34. I do not even know how I ended up here, but I thought this post was great. I don’t know who you are but definitely you are going to a famous blogger if you are not already 😉 Cheers!

댓글 남기기