Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

2009 Tw Oh Wretch Api

3,485 views

Published on

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

2009 Tw Oh Wretch Api

  1. 1. Yahoo!Kimo 2009 TW Open Hack Day
  2. 2. Wretch Open API Yahoo Asia engineering Montie Tsai
  3. 3. <ul><li>Introduction </li></ul><ul><li>Wretch API </li></ul><ul><ul><li>API List </li></ul></ul><ul><ul><li>Policy </li></ul></ul><ul><ul><li>Format </li></ul></ul><ul><li>Examples </li></ul><ul><li>References </li></ul>Agenda
  4. 4. Introduction <ul><li>Wretch Open API enables 3-parties to develop lots of interesting applications and grow up engagement for audience. </li></ul><ul><li>Basic information: </li></ul><ul><ul><li>Allow operations: GET / POST </li></ul></ul><ul><ul><li>Doc: http://tw.developer.yahoo.com/wretch/api.php </li></ul></ul><ul><ul><li>URI: </li></ul></ul><ul><ul><li>http://wretch.yahooapis.com/v1/ [API Method] ? [Parameters] </li></ul></ul>
  5. 5. Introduction <ul><li>Examples: </li></ul><ul><ul><ul><li>L+ : 店家照片 (album list, photo list) </li></ul></ul></ul><ul><ul><ul><li>Campaign: 無名生活圈 (user cover, profile, friend list) </li></ul></ul></ul>
  6. 6. Think about it <ul><li>Social </li></ul><ul><li>Platform </li></ul><ul><ul><li>Data </li></ul></ul><ul><ul><li>User </li></ul></ul><ul><ul><li>API </li></ul></ul><ul><li>Fun </li></ul>
  7. 7. API List (I) <ul><li>Site Information </li></ul><ul><ul><li>siteAlbumCategories :取得相簿全站分類列表 </li></ul></ul><ul><ul><li>siteVideoCategories :取得影音全站分類列表 </li></ul></ul><ul><ul><li>siteDiguAnnounces :取得 20 則全站最新嘀咕 </li></ul></ul><ul><li>Profile </li></ul><ul><ul><li>profileService/[guid ] :取得 user 個人資料 ( 即名片頁 ) </li></ul></ul><ul><ul><li>profileService/[guid]/idTransformation :轉換 user 的 GUID 為 WID </li></ul></ul><ul><ul><li>profileService/[guid]/cover/[cover_size ] :取得 user 大頭貼 </li></ul></ul>
  8. 8. API List (II) <ul><li>Album </li></ul><ul><ul><li>albumService/[guid ] :取得 user 相簿服務狀態 </li></ul></ul><ul><ul><li>albumService/[guid]/albums :取得 user 相簿列表 </li></ul></ul><ul><ul><li>albumService/[guid]/albums :開一本新相簿 (POST) </li></ul></ul><ul><ul><li>albumService/[guid]/categories :取得 user 相簿個人分類列表 </li></ul></ul><ul><ul><li>albumService/[guid]/album/[album_id ] :取得 user 某一本相簿之相片列表 </li></ul></ul><ul><ul><li>albumService/[guid]/album/[album_id ] :在 user 的某一本相簿上傳一張照片 (POST) </li></ul></ul><ul><ul><li>albumService/[guid]/album/[album_id]/photo/[photo_id ] :取得 user 的某一張相片的相關資訊 </li></ul></ul>
  9. 9. API List (III) <ul><li>Blog </li></ul><ul><ul><li>blogService/[guid ] :取得 user 網誌服務狀態 </li></ul></ul><ul><ul><li>blogService/[guid]/categories :取得 user 網誌個人分類列表 </li></ul></ul><ul><ul><li>blogService/[guid]/category/[category_id ] :取得 user 網誌屬於某一個人分類之文章列表 </li></ul></ul><ul><ul><li>blogService/[guid]/articles :取得 user 文章列表 </li></ul></ul><ul><ul><li>blogService/[guid]/articles :在 user 的 blog 發表文章 (POST) </li></ul></ul><ul><ul><li>blogService/[guid]/article/[article_id ] :取得 user 的某篇文章資訊及文章的前三行預覽 </li></ul></ul>
  10. 10. API List (IV) <ul><li>Video </li></ul><ul><ul><li>videoService/[guid ] :取得 user 影音服務狀態 </li></ul></ul><ul><ul><li>videoService/[guid]/videoes :取得 user 影音列表 </li></ul></ul><ul><ul><li>videoService/[guid]/videoes :上傳一則影音 (POST) </li></ul></ul><ul><ul><li>videoService/[guid]/video/[video_id ] :取得 user 某則影音及該則影音之相關資訊 </li></ul></ul><ul><ul><li>videoService/[guid]/categories :取得 user 影音個人分類列表 </li></ul></ul><ul><ul><li>videoService/[guid]/category/[category_id ] :取得 user 某個影音分類下的影音列表 </li></ul></ul>
  11. 11. API List (V) <ul><li>Friend </li></ul><ul><ul><li>friendService/[guid ] :取得 user 好友服務狀態 </li></ul></ul><ul><ul><li>friendService/[guid]/friends :取得 user 的好友列表 </li></ul></ul><ul><ul><li>friendService/[guid]/friendGroups :取得 user 的好友群組列表 </li></ul></ul><ul><ul><li>friendService/[guid]/friendGroup/[group_id ] :取得 user 的某一好友群組列表 </li></ul></ul><ul><ul><li>friendService/[guid]/mutualFriends :取得與 user 互加好友列表 </li></ul></ul><ul><ul><li>friendService/[guid]/reverseFriends :取得加此 user 為好友之列表 </li></ul></ul>
  12. 12. API List (VI) <ul><li>Digu </li></ul><ul><ul><li>diguService/[guid ] :取得 user digu 的服務狀態 </li></ul></ul><ul><ul><li>diguService/[guid]/messages :發表 ( 回覆 ) digu 訊息 (POST) </li></ul></ul><ul><ul><li>diguService/[guid]/message/[msg_id ] :取得 user 所發表的某則 digu 訊息 </li></ul></ul><ul><ul><li>diguService/[guid]/message/[msg_id ] :刪除 user 所發表的 digu 訊息 (DELETE) </li></ul></ul><ul><ul><li>diguService/[guid]/myDigus :取得 user 的 &quot; 我的嘀咕 &quot; </li></ul></ul><ul><ul><li>diguService/[guid]/allDigus :取得 user 的 &quot; 一起嘀咕 &quot; </li></ul></ul><ul><ul><li>diguService/[guid]/diguReplies :取得 user 的 &quot; 對我嘀咕 &quot; </li></ul></ul><ul><ul><li>diguService/[guid]/followers :取得 user 的訂閱列表 </li></ul></ul><ul><ul><li>diguService/[guid]/followings :取得訂閱 user 的列表 </li></ul></ul><ul><ul><li>diguService/[guid]/subscriptions :訂閱 user 的嘀咕 (POST) </li></ul></ul><ul><ul><li>diguService/[guid]/subscription :取消訂閱 user 的嘀咕 (DELETE) </li></ul></ul>
  13. 13. Data access policy (I) <ul><li>Public data: user profile, cover, connection (friend list) </li></ul><ul><ul><li>判斷條件 : </li></ul></ul><ul><ul><ul><li>不需判斷 viewer 與 owner 間的關係 -> output public data </li></ul></ul></ul><ul><li>User Content ( 除 Digu 外 ) </li></ul><ul><ul><li>判斷條件 : </li></ul></ul><ul><ul><ul><li>1. Viewer 是否等於 Owner </li></ul></ul></ul><ul><ul><ul><li>2. Owner 該 service 是否有開啟 </li></ul></ul></ul><ul><ul><ul><li>3. Viewer 與 Owner 是否互為好友 </li></ul></ul></ul><ul><ul><ul><li>§ (TRUE == 1) -> 200, output all data </li></ul></ul></ul><ul><ul><ul><li>§ (FALSE == 1) && (FASLE == 2) -> 404 </li></ul></ul></ul><ul><ul><ul><li>§ (FALSE == 1) && (TRUE == 2) && (TRUE == 3) -> 200, output public data </li></ul></ul></ul><ul><ul><ul><li>§ (FALSE == 1) && (TRUE == 2) && (FALSE == 3) -> 404 </li></ul></ul></ul>
  14. 14. Data access policy (II) <ul><li>Digu </li></ul><ul><ul><li>判斷條件 : </li></ul></ul><ul><ul><ul><li>Viewer 是否等於 Owner </li></ul></ul></ul><ul><ul><ul><li>Owner 的 digu 是否需授權 , 如果是 , 那 viewer 是否經 Owner 授權閱讀 </li></ul></ul></ul><ul><ul><ul><li>Viewer 與 Owner 是否互為好友 </li></ul></ul></ul>
  15. 15. Format Request = Action + URI Response = Status Code + body Status code Meaning of status code 200 query format 正確 , 且有 result 204 query format 正確 , 但沒有 result (ex: 相簿裡沒有相片 ) 404 query format 有誤 , 包含 : error typing, 格式錯誤 , 或是此 resource 不存在 (ex: 沒開啟服務 ) 等 406 沒有指定 valid accept format ( 包含 application/xml 及 application/json), 請用 format 參數指定或是在 request header 中的 accept 指定為 valid value
  16. 16. Examples <ul><li>GET </li></ul><?php define(&quot;API_KEY&quot;,&quot;dj0yJmk9MUdiT0lHRU92MXMzJmQ9WVdrOU5taGhjVlpNTnpJb WNHbzlNVGc0TWpJd056VTJNUS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1kNw--&quot;); define(&quot;SHARED_SECRET&quot;, &quot;f258b755c0a0b267f44dc594ec28a380cbabfc8c&quot;); define(&quot;APP_ID&quot;, &quot;6haqVL72&quot;); // Initializes session and redirects user to Yahoo! to sign in and then authorize app $yahoo_session = YahooSession::requireSession(API_KEY, SHARED_SECRET, APP_ID); $url = 'http://wretch.yahooapis.com/v1/profileService/'.$yahoo_user->guid; // Call Wretch API $response = $yahoo_session->client->get($url); print_r($response); ?>
  17. 17. Examples <ul><li>POST </li></ul><?php define(&quot;API_KEY&quot;,&quot;dj0yJmk9MUdiT0lHRU92MXMzJmQ9WVdrOU5taGhjVlpNTnpJb WNHbzlNVGc0TWpJd056VTJNUS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1kNw--&quot;); define(&quot;SHARED_SECRET&quot;, &quot;f258b755c0a0b267f44dc594ec28a380cbabfc8c&quot;); define(&quot;APP_ID&quot;, &quot;6haqVL72&quot;); // Initializes session and redirects user to Yahoo! to sign in and then authorize app $yahoo_session = YahooSession::requireSession(API_KEY, SHARED_SECRET, APP_ID); $url = 'http://wretch.yahooapis.com/v1/albumService/'.$yahoo_user->guid.’/albums’; // Call Wretch API $response = $yahoo_session->client->post($url, $contentType, $content); print_r($response); ?>
  18. 18. Example <ul><li>Upload Photo </li></ul><?php function post($url, $contentType = &quot;application/x-www-form-urlencoded&quot;, $content = array(), $timeout = NULL, $param = array() ) {         return $this->request(array(                 &quot;method&quot; => &quot;POST&quot;,                 &quot;url&quot; => $url,                 &quot;content&quot; => $content,                 &quot;contentType&quot; => $contentType,                 &quot;query&quot;   => $param,                 &quot;timeout&quot; => $timeout)); } ?> <?php $url = 'http://wretch.yahooapis.com/v1/albumService/'.$guid.'/album/23'; $filename = $_FILES['filename']['name']; $image    = base64_encode(file_get_contents($_FILES['filename']['tmp_name'])); $content = <<<XML <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <req> <title>test photo</title> <desc>test photo</desc> <filename>$filename</filename> <content>$image</content> </req> XML; $param = array('book_id' => 23); $result = $user->client->post($url, &quot; application/xml &quot;,$content, null,$param); ?>
  19. 19. References <ul><li>Yahoo! Developer Network Home </li></ul><ul><ul><li>http:// developer.yahoo.com / </li></ul></ul><ul><li>Yahoo! Oauth Quick Start Guide </li></ul><ul><ul><li>http:// developer.yahoo.com/oauth/guide </li></ul></ul>

×