SugarSync API
App支持SugarSync 網(wǎng)盤的前提:
1、AccessKeyID:xxx
2、Private Access Key:xxx
3、AppID:xxx
?
詳細的 API 總結如下:
Creating a Refresh Token
HTTP Request Example
POST https://api.sugarsync.com/app-authorization HTTP/1.1
User-Agent: Jakarta Commons-HttpClient/3.1
Host: api.sugarsync.com
Content-Length: 364
Content-Type: application/xml; charset=UTF-8
?
<?xml version="1.0" encoding="UTF-8" ?>
<appAuthorization>
<username>jsmith127@sugarsync.com</username>
<password>sugar20P$</password>
<application>/sc/10061/3_21053</application>
<accessKeyId>AKIAJTXL5NNLKNIAEORA</accessKeyId>
<privateAccessKey>QAzJKVkzSXbIXWFwEPbzmRYmP8VmdLyNn33AvjRP</privateAccessKey>
</appAuthorization>
Response Example
HTTP/1.1 201 Created
Content-Type: application/xml; charset=UTF-8
Date: Wed, 28 Mar 2012 19:29:00 GMT
Location: https://api.sugarsync.com/app-authorization/A31303036322f335f3237303337
Access-Control-Allow-Origin: *
Server: Noelios-Restlet-Engine/1.1.5
Transfer-Encoding: chunked
200-299 |
The request was successful. The refresh token was created. |
400 |
Bad request. Typically returned if required information, such as the username, was not provided as input. |
401 |
Authorization required. The presented credentials, if any, were not sufficient to access the resource. |
500-599 |
Server error. |
?
說明:
- request中header的參數(shù)都可忽略,一般的框架都會根據(jù)url和body自動填充。如果出現(xiàn)domain錯誤,表示host參數(shù)不正確,需要自己顯示的添加。
- 請求的body中為xml結構,注意格式即可。
- response中的location即為refreshToken,用于下一步請求accessToken。
- 如果有異常,建議多使用fiddler參看請求和返回內(nèi)容
- 當返回碼為400時候,多為賬號密碼錯誤,或者請求url錯誤;當為401,多為accessToken錯誤或者過期失效。后續(xù)api一樣。
?
?
Creating an Access Token
HTTP Request Example
POST https://api.sugarsync.com/authorization HTTP/1.1
User-Agent: Jakarta Commons-HttpClient/3.1
Host: api.sugarsync.com
Content-Length: 358
Content-Type: application/xml; charset=UTF-8
?
<?xml version="1.0" encoding="UTF-8" ?>
<tokenAuthRequest>
<accessKeyId>AKIAJTXL5NNLKNIAEORA</accessKeyId>
<privateAccessKey>QAzJKVkzSXbIXWFwEPbzmRYmP8VmdLyNn33AvjRP</privateAccessKey>
<refreshToken>https://api.sugarsync.com/app-authorization/A31303036322f335f3237303337</refreshToken>
</tokenAuthRequest>
Response Example
HTTP/1.1 201 Created
Content-Type: application/xml; charset=UTF-8
Date: Wed, 28 Mar 2012 19:30:44 GMT
Location: https://api.sugarsync.com/authorization/SmZ8zlrkR8j0oefVmmD4dUD83
Access-Control-Allow-Origin: *
Server: Noelios-Restlet-Engine/1.1.5
Transfer-Encoding: chunked
?
<?xml version="1.0" encoding="utf-8"?>
<authorization>
<expiration>2012-03-28T23:30:44.463+03:00</expiration>
<user>https://api.sugarsync.com/user/5664947</user>
</authorization>
?
說明:
- accessToken在response的header中,參數(shù)名為location
- body中包含過期時間和用戶信息uri
- user的最后一個數(shù)字字符串即為userid,頻繁用于后續(xù)api
- body為xml格式,需要不同平臺下的解析,iOS自帶解析委托為XMLParseDelegate
- 得到的過期時間為世界標準時間UTC格式,需要轉換為當?shù)貢r間,具體參考平臺方法
?
Retrieving User Information
HTTP Request Example
GET https://api.sugarsync.com/user/566494 HTTP/1.1
Authorization: https://api.sugarsync.com/authorization/SmZ8zlrkR8j0oefVmmD4dUD83...
User-Agent: Jakarta Commons-HttpClient/3.1
Host: api.sugarsync.com
Response Example
HTTP/1.1 200 OK
Content-Type: application/xml; charset=UTF-8
Date: Fri, 22 Oct 2011 08:01:54 GMT
Access-Control-Allow-Origin: *
Server: Noelios-Restlet-Engine/1.1.5
Transfer-Encoding: chunked
?
<?xml version="1.0" encoding="UTF-8"?>
<user>
? <username>jsmith@sugarsync.com</username>
? <nickname>jsmith</nickname>
? <quota>
??? <limit>2000000000</limit>
??? <usage>345000000</usage>
? <salt>8ijYg==</salt>
? </quota>
? <workspaces>https://api.sugarsync.com/user/566494/workspaces/contents</workspaces>
? <syncfolders>https://api.sugarsync.com/566494/folders/contents</syncfolders>
? <deleted>https://api.sugarsync.com/folder/:sc:566494:9</deleted>
? <magicBriefcase>https://api.sugarsync.com/folder/:sc:566494:2</magicBriefcase>
? <webArchive>https://api.sugarsync.com/folder/:sc:566494:1</webArchive>
? <mobilePhotos>https://api.sugarsync.com/folder/:sc:566494:3</mobilePhotos>
? <albums>https://api.sugarsync.com/566494/albums/contents<albums/>
? <recentActivities>https://api.sugarsync.com/user/566494/recentActivities/contents</recentActivities>
? <receivedShares>https://api.sugarsync.com/user/566494/receivedShares/contents</receivedShares>
? <publicLinks>https://api.sugarsync.com/user/566494/publicLinks/contents</publicLinks>
? <maximumPublicLinkSize>25</maximumPublicLinkSize>
</user>
?
說明:
1.? 至此請求頭中的Authorization都為accessToken,且必須
2.? Xml中參數(shù)很多,主要關注syncfolders和magicBriefcase兩個參數(shù)
3.? Syncfolders表示網(wǎng)盤根目錄,默認有一個子文件夾“My SugarSync”,為自動創(chuàng)建,且不能編輯該文件夾
4.? magicBriefcase表示文件夾“My SugarSync”
5.? 特別注意,Sugarsync網(wǎng)盤不支持在根目錄下創(chuàng)建文件,只允許創(chuàng)建文件夾,而My SugarSync文件夾固定且子目錄無限制,故可以在其目錄下創(chuàng)建應用根目錄
?
Retrieving Folder Contents
HTTP Request Example
GET https://api.sugarsync.com/folder/:sc:566494:5/contents HTTP/1.1
Authorization: https://api.sugarsync.com/authorization/SmZ8zlrkR8j0oefVmmD4dUD83...
User-Agent: Jakarta Commons-HttpClient/3.1
Host: api.sugarsync.com
Response Example
HTTP/1.1 200 OK
Content-Type: application/xml; charset=UTF-8
Date: Tue, 29 Nov 2011 23:06:11 GMT
Access-Control-Allow-Origin: *
Server: Noelios-Restlet-Engine/1.1.5
Transfer-Encoding: chunked
?
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<collectionContents start="0" hasMore="false" end="4">
<collection type="folder">
? <displayName>100ANDRO</displayName>
? <ref>https://api.sugarsync.com/folder/:sc:566494:6552993_17248</ref>
? <contents>https://api.sugarsync.com/folder/:sc:566494:6552993_17248/contents</contents>
</collection>
<collection type="folder">
? <displayName>2010-10-10</displayName>
? <ref>https://api.sugarsync.com/folder/:sc:566494:6552993_17250</ref>
? <contents>https://api.sugarsync.com/folder/:sc:566494:6552993_17250/contents</contents>
</collection>
<file>
? <displayName>AbeLincoln.jpg</displayName>
? <ref>https://api.sugarsync.com/file/:sc:566494:6552993_17252</ref>
? <size>38539</size>
? <lastModified>2010-02-11T15:26:52.000-08:00</lastModified>
? <mediaType>image/jpeg</mediaType>
? <presentOnServer>true</presentOnServer>
? <fileData>https://api.sugarsync.com/file/:sc:566494:6552993_17252/data</fileData>
</file>
<file>
? <displayName>GeorgeWashington.jpg</displayName>
? <ref>https://api.sugarsync.com/file/:sc:566494:6552993_17254</ref>
? <size>956022</size>
? <lastModified>2011-11-11T07:48:10.000-08:00</lastModified>
? <mediaType>image/jpeg</mediaType>
? <presentOnServer>true</presentOnServer>
? <fileData>https://api.sugarsync.com/file/:sc:566494:6552993_17254/data</fileData>
</file>
</collectionContents>
?
說明:
1.??? 經(jīng)過嘗試,發(fā)現(xiàn)實例中url代表一般路徑,但是當訪問根目錄時候,需要上一個api中得到的syncfolders參數(shù)
2.??? 一般文件或者文件夾的id為“:sc:用戶id:文件夾標識id”,可通過請求父文件夾得到contents,body中“ref”參數(shù)即為文件或者文件夾id。
3.??? 請求時候,可以在url后添加“?type=folder”或者“?type=file”,分別得到文件或者文件夾集合
4.??? 修改時間同樣為世界時間UTC
?
Creating a Folder
HTTP Request Example
POST https://api.sugarsync.com/folder/:sc:566494:4 HTTP/1.1
Authorization: https://api.sugarsync.com/authorization/SmZ8zlrkR8j0oefVmmD4dUD83...
User-Agent: Jakarta Commons-HttpClient/3.1
Host: api.sugarsync.com
Content-Length: 294
Content-Type: application/xml; charset=UTF-8
?
<?xml version="1.0" encoding="UTF-8" ?>
<folder>
?? <displayName>work-docs</displayName>
</folder>
Response Example
HTTP/1.1 201 Created
Content-Type: application/octet-stream; charset=UTF-8
Content-Length: 0
Date: Wed, 14 Dec 2011 19:35:02 GMT
Location: https://api.sugarsync.com/folder/:sc:566494:190_123294339
Access-Control-Allow-Origin: *
Server: Noelios-Restlet-Engine/1.1.5
?
說明:
1.??? 如果一直返回錯誤,保證accessToken和文件夾名正確前提下,那肯定是url有問題,文件夾父文件夾id有誤
2.??? Body中l(wèi)ocation即為創(chuàng)建文件夾的uri
?
Deleting a Folder
HTTP Request Example
DELETE https://api.sugarsync.com/folder/:sc:566494:190_123279794 HTTP/1.1
User-Agent: Jakarta Commons-HttpClient/3.1
Host: api.sugarsync.com
Content-Length: 294
Content-Type: application/xml; charset=UTF-8
Response example
HTTP/1/1 204 No Content
Content-Type: application/octet-stream; charset=UTF-8
Content-Length: 0
Date: Tue, 20 Dec 2011 18:29:20 GMT
Access-Control-Allow-Origin: *
Server: Noelios-Restlet-Engine/1.1.5
Deleting a File
HTTP Request Example
DELETE https://api.sugarsync.com/file/:sc:566494:190_138381019 HTTP/1.1
Authorization: https://api.sugarsync.com/authorization/SmZ8zlrkR8j0oefVmmD4dUD83...
User-Agent: Jakarta Commons-HttpClient/3.1
Host: api.sugarsync.com
Response Example
HTTP/1/1 204 No Content
Content-Type: application/octet-stream; charset=UTF-8
Content-Length: 0
Date: Tue, 03 Jan 2012 21:24:45 GMT
Access-Control-Allow-Origin: *
Server: Noelios-Restlet-Engine/1.1.5
?
?
Retrieving File Data
HTTP Request Example
GET https://api.sugarsync.com/file/:sc:566494:6552993_66025/data HTTP/1.1
Authorization: https://api.sugarsync.com/authorization/SmZ8zlrkR8j0oefVmmD4dUD83...
User-Agent: Jakarta Commons-HttpClient/3.1
Host: api.sugarsync.com
Response Example
HTTP/1.1 200 OK
Content-Type: application/xml; charset=UTF-8
Content-Length: 1502167
Date: Wed, 04 Jan 2012 19:31:29 GMT
Accept-Ranges: bytes
Content-Disposition: attachment; filename*=UTF-8''PineCreek5_120411.jpg
Access-Control-Allow-Origin: *
Server: Noelios-Restlet-Engine/1.1.5
說明:
url其實就是file的uri加上“/data”。
?
?
?
Creating a File
HTTP Request Example
POST https://api.sugarsync.com/folder/:sc:566494:5 HTTP/1.1
Authorization: https://api.sugarsync.com/authorization/SmZ8zlrkR8j0oefVmmD4dUD83...
User-Agent: Jakarta Commons-HttpClient/3.1
Host: api.sugarsync.com
Content-Length: 294
Content-Type: application/xml; charset=UTF-8
?
<?xml version="1.0" encoding="UTF-8" ?>
<file>
? <displayName>Winter2012.jpg</displayName>
? <mediaType>image/jpeg</mediaType>
</file>
Response Example
HTTP/1.1 201 Created
Content-Type: application/octet-stream; charset=UTF-8
Content-Length: 0
Date: Mon, 02 Jan 2012 22:27:00 GMT
Location: https://api.sugarsync.com/file/:sc:566494:190_137264710
Access-Control-Allow-Origin: *
Server: Noelios-Restlet-Engine/1.1.5
說明:
1.??? 這個api是和upload file一起使用的。因為SugarSync采用id來標識文件和文件夾,所以上傳文件之前,需要給文件先創(chuàng)建一個占位id。
2.??? 請求的body里面為創(chuàng)建的文件名和文件格式
?
Uploading File Data
HTTP Request Example
PUT https://api.sugarsync.com/file/:sc:566494:6552993_66025/data HTTP/1.1
Authorization: https://api.sugarsync.com/authorization/SmZ8zlrkR8j0oefVmmD4dUD83...
User-Agent: Jakarta Commons-HttpClient/3.1
Host: api.sugarsync.com
Content-Length: 1431
Response Example
HTTP/1.1 204 OK
Content-Type: application/octet-stream; charset=UTF-8
Content-Length: 0
Date: Wed, 04 Jan 2012 21:58:25 GMT
Access-Control-Allow-Origin: *
Server: Noelios-Restlet-Engine/1.1.5
更多文章、技術交流、商務合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
