
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BlueⓘBlog &#187; PHP</title>
	<atom:link href="http://www.blueiblog.com/ko/archives/category/%ed%94%84%eb%a1%9c%ea%b7%b8%eb%9e%98%eb%b0%8d/php-%ed%94%84%eb%a1%9c%ea%b7%b8%eb%9e%98%eb%b0%8d/feed" rel="self" type="application/rss+xml" />
	<link>http://www.blueiblog.com/ko</link>
	<description>Blueⓘ의 인터넷 아지트</description>
	<lastBuildDate>Mon, 19 Jul 2010 05:42:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>bit.ly Short URL API – PHP로 Shorten 메소드 이용해보기</title>
		<link>http://www.blueiblog.com/ko/archives/2029</link>
		<comments>http://www.blueiblog.com/ko/archives/2029#comments</comments>
		<pubDate>Sun, 07 Feb 2010 07:37:35 +0000</pubDate>
		<dc:creator>Blueⓘ</dc:creator>
				<category><![CDATA[Open API]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[bit.ly]]></category>

		<guid isPermaLink="false">http://www.blueiblog.com/ko/archives/2029</guid>
		<description><![CDATA[PHP – bit.ly Short URL API API Key 획득 및 API 목록 Shorten 메소드 설명 PHP로 Shorten 메소드 이용해보기 jQuery로 Shorten 메소드 이용해보기 그럼 앞의 두 강좌를 기본으로 PHP를 이용한 bit.ly API 코딩하기 실전으로 들어가도록 하겠습니다. 이 API 코딩법만 익히게 되면 다른 bit.ly API를 이용하는것도 어렵지 않으니 집중하고 내용을 이해 하도록 노력해 주세요. P.S. 그리고 [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; margin: 0 0 10px 20px; background: #fff;">
<fieldset>
<legend>PHP – bit.ly Short URL API</legend>
<ol style="margin: 0; padding: 0 35px 0 20px;">
<li><a href="http://www.blueiblog.com/ko/archives/1976">API Key 획득 및 API 목록</a></li>
<li><a href="http://www.blueiblog.com/ko/archives/1986">Shorten 메소드 설명</a></li>
<li><a href="http://www.blueiblog.com/ko/archives/2029">PHP로 Shorten 메소드 이용해보기</a></li>
<li><a href="http://www.blueiblog.com/ko/archives/2546">jQuery로 Shorten 메소드 이용해보기</a></li>
</ol>
</fieldset>
</div>
<p>그럼 앞의 두 강좌를 기본으로 PHP를 이용한 bit.ly API 코딩하기 실전으로 들어가도록 하겠습니다. 이 API 코딩법만 익히게 되면 다른 bit.ly API를 이용하는것도 어렵지 않으니 집중하고 내용을 이해 하도록 노력해 주세요.</p>
<p><strong>P.S. 그리고 댓글좀 써주세요 ㅡㅡ; 댓글 없는 포스팅을 보게되면 강좌를 연재할 의욕이 꺽인답니다. ^^</strong></p>
<h2>PHP로 Shorten메소드 호출</h2>
<p>이제 어떠한 방식으로 데이터를 주고받는지 알게 되었다면 PHP를 이용하여 bit.ly의 API를 이용하여 짧은 URL을 얻어오는 방법을 설명 하겠습니다. 이번 강의에서 사용될 PHP의 함수는 아래와 같습니다.</p>
<ol>
<li><strong><a href="http://kr.php.net/manual/kr/function.file-get-contents.php" target="_blank">file_get_contents</a></strong> : 로컬내 파일 또는 원격지의 파일 내용을 문자열로 가져오는 함수</li>
<li><strong><a href="http://kr.php.net/manual/kr/function.json-decode.php" target="_blank">json_decode</a></strong> : JSON으로 만들어진 문자열을 JSON 객체로 변환 해주는 함수</li>
</ol>
<p>위 두 함수는 모두 PHP 코어의 일부분으로 따로 설치 하실 필요는 없습니다. 다만 PHP 버젼에 따라 작동되지 않을 수 있습니다.</p>
<p>그럼 간단하게 긴URL을 bit.ly에 던져서 짧은URL을 얻어 출력하는 내용으로 코딩 해보도록 하겠습니다.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://api.bit.ly/shorten?version=2.0.1&amp;longUrl=http://www.blueiblog.com/ko/archives/1976&amp;login=xxxx&amp;apiKey=xxxxxxxxxxxx&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">results</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$surl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">shortCNAMEUrl</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$surl</span><span style="color: #339933;">;</span></pre></div></div>

<p>그럼 이번에는 함수를 만들어서 언제든 빼 쓸 수 있도록 해보겠습니다.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * License by Blueⓘ
 *
 * @param String longURL 짧게 변경할 긴 문자열의 URL
 * @return String 짧게 변환된 URL
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> getShortURL<span style="color: #009900;">&#40;</span><span style="color: #000088;">$longURL</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://api.bit.ly/shorten?version=2.0.1&amp;longUrl=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$longURL</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;login=xxxx&amp;apiKey=xxxxxxxxxxxx&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">results</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$surl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">shortCNAMEUrl</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$surl</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> getShortURL<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://test.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// OUTPUT : http://bit.ly/9ICmwA</span></pre></div></div>

<div style="margin: 10px 0 10px 0; border: 3px solid #6FA7D1; display: inline-block; width: 720px;">
<p style="padding: 0 0 0 20px; margin: 0; line-height: 30px; border-bottom: 1px solid #6FA7D1; background: #CBDEED; font-weight: bold;">이 글이 도움이 않되셨더라도 왼쪽 아래에 있는 손 모양의 추천을 눌러주세요...^^</p>
<ul style="list-style-type: none; margin: 0;; padding: 0;">
<li style="width: 100px; float: left; padding-left: 30px; padding-top: 5px; margin: 5px 0;">
<embed src="http://api.v.daum.net/static/recombox3.swf?nid=5742339" quality="high" bgcolor="#ffffff" width="67" height="80" type="application/x-shockwave-flash"></embed>
</li><li style="height: 100px; overflow: hidden; padding: 20px 0 0 0; text-align: center; margin-bottom: -20px;">
<script type='text/javascript'><!--
google_ad_client = 'pub-1866412074966530';
/* 468x60, 작성됨 09. 10. 29 */
google_ad_slot = '9943142053';
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type='text/javascript'
src='http://pagead2.googlesyndication.com/pagead/show_ads.js'>
</script>
</li>
</ul></textarea>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.blueiblog.com/ko/archives/2029/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>bit.ly Short URL API – Shorten 메소드 설명</title>
		<link>http://www.blueiblog.com/ko/archives/1986</link>
		<comments>http://www.blueiblog.com/ko/archives/1986#comments</comments>
		<pubDate>Sat, 06 Feb 2010 02:41:49 +0000</pubDate>
		<dc:creator>Blueⓘ</dc:creator>
				<category><![CDATA[Open API]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[bit.ly]]></category>

		<guid isPermaLink="false">http://www.blueiblog.com/ko/archives/1986</guid>
		<description><![CDATA[PHP – bit.ly Short URL API API Key 획득 및 API 목록 Shorten 메소드 설명 PHP로 Shorten 메소드 이용해보기 jQuery로 Shorten 메소드 이용해보기 이번에는 앞서 설명했던 내용을 토대로 shorten메소드에 대해서 알아보도록 하겠습니다. shorten메소드는 bit.ly의 API중 우리가 가장 많이 사용하게 될 메소드입니다. shorten메소드는 http://www.blueiblog.com/ko/archives/1976 와 같은 긴 주소를 http://bit.ly/b4ihSW 와 같이 짧게 줄여주는 역활을 합니다. 그럼 [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; margin: 0 0 10px 20px; background: #fff;">
<fieldset>
<legend>PHP – bit.ly Short URL API</legend>
<ol style="margin: 0; padding: 0 35px 0 20px;">
<li><a href="http://www.blueiblog.com/ko/archives/1976">API Key 획득 및 API 목록</a></li>
<li><a href="http://www.blueiblog.com/ko/archives/1986">Shorten 메소드 설명</a></li>
<li><a href="http://www.blueiblog.com/ko/archives/2029">PHP로 Shorten 메소드 이용해보기</a></li>
<li><a href="http://www.blueiblog.com/ko/archives/2546">jQuery로 Shorten 메소드 이용해보기</a></li>
</ol>
</fieldset>
</div>
<p>이번에는 앞서 설명했던 내용을 토대로 shorten메소드에 대해서 알아보도록 하겠습니다. shorten메소드는 bit.ly의 API중 우리가 가장 많이 사용하게 될 메소드입니다. shorten메소드는 http://www.blueiblog.com/ko/archives/1976 와 같은 긴 주소를 http://bit.ly/b4ihSW 와 같이 짧게 줄여주는 역활을 합니다.</p>
<p>그럼 shorten메소드의 사용법에 대해서 알아보도록 하겠습니다.</p>
<h2>Shorten Method 요청 및 결과</h2>
<p>Shorten메소드는 아래와 같은 파라미터를 입력해야 사용 할 수 있습니다. 입력해야 할 파라미터와 그 설명은 아래와 같습니다.</p>
<fieldset>
<legend>Parameter</legend>
<ul style="margin-top: 0; margin-bottom: 0;">
<li><strong>version</strong> : API 버젼을 입력하는 기본 파라미터(모든 함수 동일)</li>
<li><strong>login</strong> : API를 이용할 아이디(모든 함수 동일)</li>
<li><strong>apiKey</strong> : API를 이용할 Key(모든 함수 동일)</li>
<li><strong>format</strong> : xml과 json중 선택 가능, format파라미터를 입력하지 않으면 JSON으로 반환</li>
<li><strong style="color:blue;">longUrl</strong> : 짧은 URL로 변경할 원래 URL</li>
</ul>
</fieldset>
<p>그럼 위 메소드를 어떻게 사용하는지 알아보도록 하겠습니다. 우선 http://www.blueiblog.com/ko/archives/1976 주소를 짧게 변경하고 싶다면 아래와 같이 shorten메소드를 호출 해 보겠습니다. 브라우저의 주소 입력 창에 아래와 같이 입력해보세요. <span style="text-decoration: underline;">(아래 이미지를 클릭하시면 원본 사이즈로 보실 수 있습니다.)</span></p>
<p><a href="http://www.blueiblog.com/ko/wp-content/uploads/2010/02/2010-02-06_112346.gif"><img src="http://www.blueiblog.com/ko/wp-content/uploads/2010/02/2010-02-06_112346-720x35.gif" alt="" title="2010-02-06_112346" width="720" height="35" class="aligncenter size-large wp-image-1994" /></a></p>

<div class="wp_syntax"><div class="code"><pre class="url" style="font-family:monospace;">http://api.bit.ly/shorten?version=2.0.1&amp;longUrl=http://www.blueiblog.com/ko/archives/1976&amp;login=xxxx&amp;apiKey=xxxxxxxxxxxx</pre></div></div>

<p>이와 같이 브라우져에 데이터를 요청하게 되면 다음과 같은 결과를 얻을 수 있습니다.</p>

<div class="wp_syntax"><div class="code"><pre class="json" style="font-family:monospace;">{
    &quot;errorCode&quot;: 0, 
    &quot;errorMessage&quot;: &quot;&quot;, 
    &quot;results&quot;: {
        &quot;http://www.blueiblog.com/ko/archives/1976&quot;: {
            &quot;hash&quot;: &quot;b4ihSW&quot;, 
            &quot;shortCNAMEUrl&quot;: &quot;http://bit.ly/9pTARb&quot;, 
            &quot;shortKeywordUrl&quot;: &quot;&quot;, 
            &quot;shortUrl&quot;: &quot;http://bit.ly/9pTARb&quot;, 
            &quot;userHash&quot;: &quot;9pTARb&quot;
        }
    }, 
    &quot;statusCode&quot;: &quot;OK&quot;
}</pre></div></div>

<p>위 결과 처럼 Shorten메소드의 호출 결과는 JSON데이터로 반환 됩니다. format파라미터를 xml로 입력하면 xml로 결과를 반환 받을 수 있습니다. 아래는 xml로 반환 받은 경우의 결과 데이터 입니다.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bitly<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;errorCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/errorCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;errorMessage</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;results<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;nodeKeyVal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shortKeywordUrl</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hash<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>b4ihSW<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hash<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;userHash<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>9pTARb<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/userHash<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;nodeKey<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://www.blueiblog.com/ko/archives/1976<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/nodeKey<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shortUrl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://bit.ly/9pTARb<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shortUrl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shortCNAMEUrl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://bit.ly/9pTARb<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shortCNAMEUrl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/nodeKeyVal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/results<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;statusCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>OK<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/statusCode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bitly<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>위 결과 처럼 xml로도 데이터를 반환 받을 수 있습니다. 하지만 우리는 기본포맷인 json으로 받은 데이터를 이용하여 프로그램을 작성 할 것입니다.</p>
<div style="margin: 10px 0 10px 0; border: 3px solid #6FA7D1; display: inline-block; width: 720px;">
<p style="padding: 0 0 0 20px; margin: 0; line-height: 30px; border-bottom: 1px solid #6FA7D1; background: #CBDEED; font-weight: bold;">이 글이 도움이 않되셨더라도 왼쪽 아래에 있는 손 모양의 추천을 눌러주세요...^^</p>
<ul style="list-style-type: none; margin: 0;; padding: 0;">
<li style="width: 100px; float: left; padding-left: 30px; padding-top: 5px; margin: 5px 0;">
<embed src="http://api.v.daum.net/static/recombox3.swf?nid=5731093" quality="high" bgcolor="#ffffff" width="67" height="80" type="application/x-shockwave-flash"></embed>
</li><li style="height: 100px; overflow: hidden; padding: 20px 0 0 0; text-align: center; margin-bottom: -20px;">
<script type='text/javascript'><!--
google_ad_client = 'pub-1866412074966530';
/* 468x60, 작성됨 09. 10. 29 */
google_ad_slot = '9943142053';
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type='text/javascript'
src='http://pagead2.googlesyndication.com/pagead/show_ads.js'>
</script>
</li>
</ul></textarea>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.blueiblog.com/ko/archives/1986/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>bit.ly Short URL API &#8211; API Key 획득 및 API 목록</title>
		<link>http://www.blueiblog.com/ko/archives/1976</link>
		<comments>http://www.blueiblog.com/ko/archives/1976#comments</comments>
		<pubDate>Fri, 05 Feb 2010 07:56:41 +0000</pubDate>
		<dc:creator>Blueⓘ</dc:creator>
				<category><![CDATA[Open API]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[bit.ly]]></category>

		<guid isPermaLink="false">http://www.blueiblog.com/ko/archives/1976</guid>
		<description><![CDATA[PHP – bit.ly Short URL API API Key 획득 및 API 목록 Shorten 메소드 설명 PHP로 Shorten 메소드 이용해보기 jQuery로 Shorten 메소드 이용해보기 마이크로 블로깅으로 인해 숏URL 서비스가 인기를 얻는 세상이 왔습니다. 옛날 같으면 쓰지도 않던 기능인데 말이죠 ^^ 저 역시 블로그 글을 출판하게 되면 자동으로 트위터에 포스트의 제목과 URL을 추가하여 출판하고 있습니다. 하지만 역시 [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; margin: 0 0 10px 20px; background: #fff;">
<fieldset>
<legend>PHP – bit.ly Short URL API</legend>
<ol style="margin: 0; padding: 0 35px 0 20px;">
<li><a href="http://www.blueiblog.com/ko/archives/1976">API Key 획득 및 API 목록</a></li>
<li><a href="http://www.blueiblog.com/ko/archives/1986">Shorten 메소드 설명</a></li>
<li><a href="http://www.blueiblog.com/ko/archives/2029">PHP로 Shorten 메소드 이용해보기</a></li>
<li><a href="http://www.blueiblog.com/ko/archives/2546">jQuery로 Shorten 메소드 이용해보기</a></li>
</ol>
</fieldset>
</div>
<p>마이크로 블로깅으로 인해 숏URL 서비스가 인기를 얻는 세상이 왔습니다. 옛날 같으면 쓰지도 않던 기능인데 말이죠 ^^</p>
<p>저 역시 블로그 글을 출판하게 되면 자동으로 트위터에 포스트의 제목과 URL을 추가하여 출판하고 있습니다. 하지만 역시 블로그의 주소는 길기에&#8230; 어쩔수 없이 Short URL기능을 이용해야 합니다. 그래서 <a href="http://bit.ly" target="_blank">bit.ly</a>의 Short URL API에 대해 알아 보았습니다.</p>
<p>그럼 PHP를 이용하여 <a href="http://bit.ly" target="_blank">bit.ly</a>의 Short URL을 가져오는 방법에 대해서 알아보도록 하겠습니다.</p>
<h2>bit.ly의 API Key 얻기</h2>
<p>여느 API와 마찬가지로 API를 이용하기 위해서는 API Key를 얻어야 합니다. 우선 <a href="http://bit.ly" target="_blank">http://bit.ly</a>의 홈페이지로 이동 한 후 회원가입을 합니다. 회원 가입후 어카운트 정보를 확인하면 아래와 같이 API Key가 보여집니다. (제 API Key 보안을 위해 ^^; 해당 부분은 모자이크 처리 했습니다.)</p>
<p><a href="http://www.blueiblog.com/ko/wp-content/uploads/2010/02/2010-02-05_164433.gif"><img src="http://www.blueiblog.com/ko/wp-content/uploads/2010/02/2010-02-05_164433-720x340.gif" alt="" title="2010-02-05_164433" width="720" height="340" class="aligncenter size-large wp-image-1978" /></a></p>
<p>물론 이렇게 얻은 API Key가 유출되었다면 우측의 Reset키를 누르시면 새로운 API Key를 발급 받으실수 있습니다.</p>
<h2>bit.ly API 목록</h2>
<p><a href="http://bit.ly" target="_blank">bit.ly</a>는 다른 OPEN API에 비해 API의 종류가 매우 간단합니다. 우선 API 리스트는 아래와 같습니다.</p>
<ol>
<li><strong>shorten</strong> : 우리가 제일 필요로 하는 API로 URL을 bit.ly의 짧은 URL로 바꾸어주는 API입니다.</li>
<li><strong>expand</strong> : bit.ly/xxxxx 형식으로 되어 있는 Short URL을 원래의 URL로 바꾸어주는 API입니다.</li>
<li><strong>info</strong> : bit.ly의 Short URL에 해당하는 정보를 보여주는 API입니다.</li>
<li><strong>stats</strong> : bit.ly Short URL의 트래픽 및 레퍼러 정보를 보여주는 API입니다.</li>
<li><strong>errors</strong> : bit.ly에서 사용되는 ERROR CODE를 보여주는 API입니다.</li>
</ol>
<p>P.S. bit.ly의 API 문서 페이지는 <a href="http://code.google.com/p/bitly-api/wiki/ApiDocumentation" target="_blank">http://code.google.com/p/bitly-api/wiki/ApiDocumentation</a> 입니다.</p>
<div style="margin: 10px 0 10px 0; border: 3px solid #6FA7D1; display: inline-block; width: 720px;">
<p style="padding: 0 0 0 20px; margin: 0; line-height: 30px; border-bottom: 1px solid #6FA7D1; background: #CBDEED; font-weight: bold;">이 글이 도움이 않되셨더라도 왼쪽 아래에 있는 손 모양의 추천을 눌러주세요...^^</p>
<ul style="list-style-type: none; margin: 0;; padding: 0;">
<li style="width: 100px; float: left; padding-left: 30px; padding-top: 5px; margin: 5px 0;">
<embed src="http://api.v.daum.net/static/recombox3.swf?nid=5723626" quality="high" bgcolor="#ffffff" width="67" height="80" type="application/x-shockwave-flash"></embed>
</li><li style="height: 100px; overflow: hidden; padding: 20px 0 0 0; text-align: center; margin-bottom: -20px;">
<script type='text/javascript'><!--
google_ad_client = 'pub-1866412074966530';
/* 468x60, 작성됨 09. 10. 29 */
google_ad_slot = '9943142053';
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type='text/javascript'
src='http://pagead2.googlesyndication.com/pagead/show_ads.js'>
</script>
</li>
</ul></textarea>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.blueiblog.com/ko/archives/1976/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ID3_GET_VERSION</title>
		<link>http://www.blueiblog.com/ko/archives/694</link>
		<comments>http://www.blueiblog.com/ko/archives/694#comments</comments>
		<pubDate>Tue, 07 Jul 2009 01:12:51 +0000</pubDate>
		<dc:creator>Blueⓘ</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ID3]]></category>
		<category><![CDATA[id3_get_version]]></category>
		<category><![CDATA[MP3]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.blueiblog.com/ko/archives/694</guid>
		<description><![CDATA[MP3에서 처음 태그를 가져오기전에 ID3태그의 버젼을 확인 할 필요가 있다. 이 때 사용하는 함수가 id3_get_version이다. ID3태그는 1.x의 규격과 2.x의 규격이 나와 있다. 1.x와 2.x는 서로 규격이 다르기때문에 호환되지 않으며 이때문에 PHP에서도 tag를 가져오기 위해 VERSION을 확인 할 필요가 있다. 이 때 사용되는 함수가 id3_get_version이다. 사용법은 다음과 같다. 1 2 3 4 5 6 7 8 [...]]]></description>
			<content:encoded><![CDATA[<p>MP3에서 처음 태그를 가져오기전에 ID3태그의 버젼을 확인 할 필요가 있다. 이 때 사용하는 함수가 <strong>id3_get_version</strong>이다.</p>
<p>ID3태그는 1.x의 규격과 2.x의 규격이 나와 있다. 1.x와 2.x는 서로 규격이 다르기때문에 호환되지 않으며 이때문에 PHP에서도 tag를 가져오기 위해 VERSION을 확인 할 필요가 있다. 이 때 사용되는 함수가 <strong>id3_get_version</strong>이다.</p>
<p>사용법은 다음과 같다.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$version</span> <span style="color: #339933;">=</span> <span style="color: #990000;">id3_get_version</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;path/to/example.mp3&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$version</span> <span style="color: #339933;">&amp;</span> ID3_V1_0<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Contains a 1.x tag<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$version</span> <span style="color: #339933;">&amp;</span> ID3_V1_1<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Contains a 1.1 tag<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$version</span> <span style="color: #339933;">&amp;</span> ID3_V2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Contains a 2.x tag<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.blueiblog.com/ko/archives/694/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP, JavaScript로 byte를 Kb, Mb, Gb, Tb로 변환</title>
		<link>http://www.blueiblog.com/ko/archives/642</link>
		<comments>http://www.blueiblog.com/ko/archives/642#comments</comments>
		<pubDate>Fri, 26 Jun 2009 04:45:11 +0000</pubDate>
		<dc:creator>Blueⓘ</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[바이트변환]]></category>

		<guid isPermaLink="false">http://www.blueiblog.com/ko/archives/642</guid>
		<description><![CDATA[오랜만에 아니 현재 블로그로 재 오픈한뒤 처음으로 소스를 올리는군요 ^^ 아래는 자료실등을 만들때 많이 사용하는 byte를 Kb, Mb등으로 변환해주는 함수입니다. PHPSCHOOL의 팁텍에 올라온 글에 타이니님이 달으신 댓글내용중 log로 변환하면 이렇게 간단해진다... 라는 부분 ^^]]></description>
			<content:encoded><![CDATA[<p>오랜만에 아니 현재 블로그로 재 오픈한뒤 처음으로 소스를 올리는군요 ^^ </p>
<p>아래는 자료실등을 만들때 많이 사용하는 byte를 Kb, Mb등으로 변환해주는 함수입니다. 로그를 사용하여 간단하게 처리 합니다.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * byte를 용량에 따라 b, kb, mb, gb, tb로 계산하여 리턴함 (PHP)
 *
 * @param int bytes
 * @return String
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> byteConvert<span style="color: #009900;">&#40;</span><span style="color: #000088;">$bytes</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'B'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Kb'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'MB'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'GB'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'TB'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'PB'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$e</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bytes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%.2f '</span><span style="color: #339933;">.</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$bytes</span><span style="color: #339933;">/</span><span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1024</span><span style="color: #339933;">,</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * byte를 용량에 따라 b, kb, mb, gb, tb로 계산하여 리턴함 (JavaScript)
 *
 * @param int bytes
 * @return String
 */</span>
<span style="color: #003366; font-weight: bold;">function</span> byteConvertor<span style="color: #009900;">&#40;</span>bytes<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	bytes <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>bytes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'bytes'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'KB'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'MB'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'GB'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'TB'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'PB'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> e <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>bytes<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>Math.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1024</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;-Infinity&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;0 &quot;</span><span style="color: #339933;">+</span>s<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
	<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>bytes<span style="color: #339933;">/</span>Math.<span style="color: #660066;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1024</span><span style="color: #339933;">,</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toFixed</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot; &quot;</span><span style="color: #339933;">+</span>s<span style="color: #009900;">&#91;</span>e<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>자바스크립트에서는 if(e == &#8220;-Infinity&#8221;)부분을 추가 했습니다. 이는 0바이트가 넘어갈때 나는 오류를 처리하기 위함입니다.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blueiblog.com/ko/archives/642/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
