2009 tw oh wretch api

19
Yahoo!Kimo 2009 TW Open Hack Day

Upload: jh-lee

Post on 20-Jan-2015

3.224 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: 2009 Tw Oh Wretch Api

Yahoo!Kimo 2009 TW Open Hack Day

Page 2: 2009 Tw Oh Wretch Api

Wretch Open APIWretch Open APIYahoo Asia engineering

Montie Tsai

Page 3: 2009 Tw Oh Wretch Api

3

• IntroductionIntroduction

• Wretch APIWretch API- API ListAPI List- PolicyPolicy- FormatFormat

• ExamplesExamples

• ReferencesReferences

Agenda

Page 4: 2009 Tw Oh Wretch Api

Introduction

• Wretch Open API enables 3-parties to develop lots of interesting applications and grow up engagement for audience.

• Basic information:-Allow operations: GET / POST-Doc: http://tw.developer.yahoo.com/wretch/api.php-URI: http://wretch.yahooapis.com/v1/[API Method]?[Parameters]

4

Page 5: 2009 Tw Oh Wretch Api

Introduction

• Examples:8 L+ : 店家照片 (album list, photo list)8 Campaign: 無名生活圈 (user cover, profile, friend list)

Page 6: 2009 Tw Oh Wretch Api

Think about it

•Social

•Platform-Data-User-API

•Fun

Page 7: 2009 Tw Oh Wretch Api

API List (I)

• Site Information- siteAlbumCategories:取得相簿全站分類列表- siteVideoCategories:取得影音全站分類列表- siteDiguAnnounces:取得 20 則全站最新嘀咕

• Profile- profileService/[guid]:取得 user 個人資料 ( 即名片頁 )- profileService/[guid]/idTransformation:轉換 user 的 GUID 為 WID - profileService/[guid]/cover/[cover_size]:取得 user 大頭貼

7

Page 8: 2009 Tw Oh Wretch Api

API List (II)

• Album- albumService/[guid]:取得 user 相簿服務狀態 - albumService/[guid]/albums:取得 user 相簿列表 - albumService/[guid]/albums:開一本新相簿 (POST) - albumService/[guid]/categories:取得 user 相簿個人分類列表 - albumService/[guid]/album/[album_id]:取得 user 某一本相簿之相片列表- albumService/[guid]/album/[album_id]:在 user 的某一本相簿上傳一張照片 (P

OST)- albumService/[guid]/album/[album_id]/photo/[photo_id]:取得 user 的某一張相

片的相關資訊

8

Page 9: 2009 Tw Oh Wretch Api

API List (III)

• Blog- blogService/[guid]:取得 user 網誌服務狀態- blogService/[guid]/categories:取得 user 網誌個人分類列表 - blogService/[guid]/category/[category_id]:取得 user 網誌屬於某一個人分類之文

章列表- blogService/[guid]/articles:取得 user 文章列表- blogService/[guid]/articles:在 user 的 blog 發表文章 (POST) - blogService/[guid]/article/[article_id]:取得 user 的某篇文章資訊及文章的前三行

預覽

9

Page 10: 2009 Tw Oh Wretch Api

API List (IV)

• Video- videoService/[guid]:取得 user 影音服務狀態- videoService/[guid]/videoes:取得 user 影音列表 - videoService/[guid]/videoes:上傳一則影音 (POST) - videoService/[guid]/video/[video_id]:取得 user 某則影音及該則影音之相關資訊- videoService/[guid]/categories:取得 user 影音個人分類列表 - videoService/[guid]/category/[category_id]:取得 user 某個影音分類下的影音列表

10

Page 11: 2009 Tw Oh Wretch Api

API List (V)

• Friend- friendService/[guid]:取得 user 好友服務狀態- friendService/[guid]/friends:取得 user 的好友列表 - friendService/[guid]/friendGroups:取得 user 的好友群組列表 - friendService/[guid]/friendGroup/[group_id]:取得 user 的某一好友群組列表 - friendService/[guid]/mutualFriends:取得與 user 互加好友列表 - friendService/[guid]/reverseFriends:取得加此 user 為好友之列表

11

Page 12: 2009 Tw Oh Wretch Api

API List (VI)

• Digu- diguService/[guid]:取得 user digu 的服務狀態- diguService/[guid]/messages:發表 ( 回覆 ) digu 訊息 (POST) - diguService/[guid]/message/[msg_id]:取得 user 所發表的某則 digu 訊息 - diguService/[guid]/message/[msg_id]:刪除 user 所發表的 digu 訊息 (DELETE)- diguService/[guid]/myDigus:取得 user 的 " 我的嘀咕 " - diguService/[guid]/allDigus:取得 user 的 " 一起嘀咕 " - diguService/[guid]/diguReplies:取得 user 的 " 對我嘀咕 " - diguService/[guid]/followers:取得 user 的訂閱列表 - diguService/[guid]/followings :取得訂閱 user 的列表 - diguService/[guid]/subscriptions :訂閱 user 的嘀咕 (POST) - diguService/[guid]/subscription :取消訂閱 user 的嘀咕 (DELETE)

12

Page 13: 2009 Tw Oh Wretch Api

Data access policy (I)

• Public data: user profile, cover, connection (friend list)-判斷條件 :

8 不需判斷 viewer 與 owner 間的關係 → output public data

• User Content ( 除 Digu 外 )-判斷條件 :

1. Viewer 是否等於 Owner2. Owner 該 service 是否有開啟3. Viewer 與 Owner 是否互為好友

§ (TRUE == 1) → 200, output all data§ (FALSE == 1) && (FASLE == 2) → 404§ (FALSE == 1) && (TRUE == 2) && (TRUE == 3) → 200, output public data§ (FALSE == 1) && (TRUE == 2) && (FALSE == 3) → 404

13

Page 14: 2009 Tw Oh Wretch Api

Data access policy (II)

• Digu-判斷條件 :

8 Viewer 是否等於 Owner8 Owner 的 digu 是否需授權 , 如果是 , 那 viewer 是否經 Owner

授權閱讀8 Viewer 與 Owner 是否互為好友

14

Page 15: 2009 Tw Oh Wretch Api

Format

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

15

Request = Action + URIResponse = Status Code + body

Page 16: 2009 Tw Oh Wretch Api

Examples

• GET

16

<?php define("API_KEY","dj0yJmk9MUdiT0lHRU92MXMzJmQ9WVdrOU5taGhjVlpNTnpJb WNHbzlNVGc0TWpJd056VTJNUS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1kNw--"); define("SHARED_SECRET", "f258b755c0a0b267f44dc594ec28a380cbabfc8c"); define("APP_ID", "6haqVL72");

// 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);?>

Page 17: 2009 Tw Oh Wretch Api

Examples

• POST

17

<?php define("API_KEY","dj0yJmk9MUdiT0lHRU92MXMzJmQ9WVdrOU5taGhjVlpNTnpJb WNHbzlNVGc0TWpJd056VTJNUS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1kNw--"); define("SHARED_SECRET", "f258b755c0a0b267f44dc594ec28a380cbabfc8c"); define("APP_ID", "6haqVL72");

// 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);?>

Page 18: 2009 Tw Oh Wretch Api

Example

• Upload Photo<?php function post($url, $contentType = "application/x-www-form-urlencoded", $content = array(), $timeout = NULL, $param = array() ) {        return $this->request(array(                "method" => "POST",                "url" => $url,                "content" => $content,                "contentType" => $contentType,                "query"   => $param,                "timeout" => $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="1.0" encoding="utf-8"?><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, "application/xml",$content, null,$param);

?>

Page 19: 2009 Tw Oh Wretch Api

References

•Yahoo! Developer Network Home-http://developer.yahoo.com/

•Yahoo! Oauth Quick Start Guide-http://developer.yahoo.com/oauth/guide

19