当前位置: 首页 > 工具软件 > SugarSync > 使用案例 >

SugarSync的API总结

白坚壁
2023-12-01

SugarSync API

App支持SugarSync网盘的前提:

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.

 

说明:

  1. request中header的参数都可忽略,一般的框架都会根据url和body自动填充。如果出现domain错误,表示host参数不正确,需要自己显示的添加。
  2. 请求的body中为xml结构,注意格式即可。
  3. response中的location即为refreshToken,用于下一步请求accessToken。
  4. 如果有异常,建议多使用fiddler参看请求和返回内容
  5. 当返回码为400时候,多为账号密码错误,或者请求url错误;当为401,多为accessToken错误或者过期失效。后续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中,参数名为location
  2. body中包含过期时间和用户信息uri
  3. user的最后一个数字字符串即为userid,频繁用于后续api
  4. body为xml格式,需要不同平台下的解析,iOS自带解析委托为XMLParseDelegate
  5. 得到的过期时间为世界标准时间UTC格式,需要转换为当地时间,具体参考平台方法

 

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中参数很多,主要关注syncfolders和magicBriefcase两个参数

3.  Syncfolders表示网盘根目录,默认有一个子文件夹“My SugarSync”,为自动创建,且不能编辑该文件夹

4.  magicBriefcase表示文件夹“My SugarSync”

5.  特别注意,Sugarsync网盘不支持在根目录下创建文件,只允许创建文件夹,而My SugarSync文件夹固定且子目录无限制,故可以在其目录下创建应用根目录

 

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.    经过尝试,发现实例中url代表一般路径,但是当访问根目录时候,需要上一个api中得到的syncfolders参数

2.    一般文件或者文件夹的id为“:sc:用户id:文件夹标识id”,可通过请求父文件夹得到contents,body中“ref”参数即为文件或者文件夹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中location即为创建文件夹的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来标识文件和文件夹,所以上传文件之前,需要给文件先创建一个占位id。

2.    请求的body里面为创建的文件名和文件格式

 

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

转载于:https://www.cnblogs.com/A-Long-Way-Chris/p/3621422.html

 类似资料: