日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

SugarSync的API總結(jié)

系統(tǒng) 2196 0

SugarSync API

App支持SugarSync 網(wǎng)盤的前提:

1、AccessKeyID:xxx

2、Private Access Key:xxx

3、AppID:xxx

?

詳細(xì)的 API 總結(jié)如下:

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.

?

說明:

  1. request中header的參數(shù)都可忽略,一般的框架都會(huì)根據(jù)url和body自動(dòng)填充。如果出現(xiàn)domain錯(cuò)誤,表示host參數(shù)不正確,需要自己顯示的添加。
  2. 請(qǐng)求的body中為xml結(jié)構(gòu),注意格式即可。
  3. response中的location即為refreshToken,用于下一步請(qǐng)求accessToken。
  4. 如果有異常,建議多使用fiddler參看請(qǐng)求和返回內(nèi)容
  5. 當(dāng)返回碼為400時(shí)候,多為賬號(hào)密碼錯(cuò)誤,或者請(qǐng)求url錯(cuò)誤;當(dāng)為401,多為accessToken錯(cuò)誤或者過期失效。后續(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>
    

?

說明:

  1. accessToken在response的header中,參數(shù)名為location
  2. body中包含過期時(shí)間和用戶信息uri
  3. user的最后一個(gè)數(shù)字字符串即為userid,頻繁用于后續(xù)api
  4. body為xml格式,需要不同平臺(tái)下的解析,iOS自帶解析委托為XMLParseDelegate
  5. 得到的過期時(shí)間為世界標(biāo)準(zhǔn)時(shí)間UTC格式,需要轉(zhuǎn)換為當(dāng)?shù)貢r(shí)間,具體參考平臺(tái)方法

?

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.? 至此請(qǐng)求頭中的Authorization都為accessToken,且必須

2.? Xml中參數(shù)很多,主要關(guān)注syncfolders和magicBriefcase兩個(gè)參數(shù)

3.? Syncfolders表示網(wǎng)盤根目錄,默認(rèn)有一個(gè)子文件夾“My SugarSync”,為自動(dòng)創(chuàng)建,且不能編輯該文件夾

4.? magicBriefcase表示文件夾“My SugarSync”

5.? 特別注意,Sugarsync網(wǎng)盤不支持在根目錄下創(chuàng)建文件,只允許創(chuàng)建文件夾,而My SugarSync文件夾固定且子目錄無限制,故可以在其目錄下創(chuàng)建應(yī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)實(shí)例中url代表一般路徑,但是當(dāng)訪問根目錄時(shí)候,需要上一個(gè)api中得到的syncfolders參數(shù)

2.??? 一般文件或者文件夾的id為“:sc:用戶id:文件夾標(biāo)識(shí)id”,可通過請(qǐng)求父文件夾得到contents,body中“ref”參數(shù)即為文件或者文件夾id。

3.??? 請(qǐng)求時(shí)候,可以在url后添加“?type=folder”或者“?type=file”,分別得到文件或者文件夾集合

4.??? 修改時(shí)間同樣為世界時(shí)間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.??? 如果一直返回錯(cuò)誤,保證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其實(shí)就是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.??? 這個(gè)api是和upload file一起使用的。因?yàn)镾ugarSync采用id來標(biāo)識(shí)文件和文件夾,所以上傳文件之前,需要給文件先創(chuàng)建一個(gè)占位id。

2.??? 請(qǐng)求的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
    

SugarSync的API總結(jié)


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 剑阁县| 古田县| 调兵山市| 武冈市| 特克斯县| 蓝田县| 西安市| 高州市| 湖州市| 方正县| 昂仁县| 道孚县| 阿坝县| 东宁县| 石棉县| 浦东新区| 边坝县| 嘉兴市| 玉树县| 玉山县| 旬邑县| 科技| 吉安县| 南投市| 兴隆县| 宁波市| 休宁县| 仁寿县| 昆明市| 贵州省| 威海市| 修武县| 霍山县| 鲜城| 平安县| 临邑县| 佛教| 滁州市| 车险| 贵溪市| 城步|