SugarSync的API总结
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. |
说明:
- request中header的参数都可忽略,一般的框架都会根据url和body自动填充。如果出现domain错误,表示host参数不正确,需要自己显示的添加。
- 请求的body中为xml结构,注意格式即可。
- response中的location即为refreshToken,用于下一步请求accessToken。
- 如果有异常,建议多使用fiddler参看请求和返回内容
- 当返回码为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>
说明:
- accessToken在response的header中,参数名为location
- body中包含过期时间和用户信息uri
- user的最后一个数字字符串即为userid,频繁用于后续api
- body为xml格式,需要不同平台下的解析,iOS自带解析委托为XMLParseDelegate
- 得到的过期时间为世界标准时间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
SugarSync的API总结的更多相关文章
- 干货来袭-整套完整安全的API接口解决方案
在各种手机APP泛滥的现在,背后都有同样泛滥的API接口在支撑,其中鱼龙混杂,直接裸奔的WEB API大量存在,安全性令人堪优 在以前WEB API概念没有很普及的时候,都采用自已定义的接口和结构,对 ...
- 12306官方火车票Api接口
2017,现在已进入春运期间,真的是一票难求,深有体会.各种购票抢票软件应运而生,也有购买加速包提高抢票几率,可以理解为变相的黄牛.对于技术人员,虽然写一个抢票软件还是比较难的,但是还是简单看看123 ...
- 几个有趣的WEB设备API(二)
浏览器和设备之间还有很多有趣的接口, 1.屏幕朝向接口 浏览器有两种方法来监听屏幕朝向,看是横屏还是竖屏. (1)使用css媒体查询的方法 /* 竖屏 */ @media screen and (or ...
- html5 canvas常用api总结(三)--图像变换API
canvas的图像变换api,可以帮助我们更加方便的绘画出一些酷炫的效果,也可以用来制作动画.接下来将总结一下canvas的变换方法,文末有一个例子来更加深刻的了解和利用这几个api. 1.画布旋转a ...
- JavaScript 对数据处理的5个API
JavaScript对数据处理包括向上取整.向下取整.四舍五入.固定精度和固定长度5种方式,分别对应ceil,floor,round,toFixed,toPrecision等5个API,本文将对这5个 ...
- ES5对Array增强的9个API
为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...
- javascript的api设计原则
前言 本篇博文来自一次公司内部的前端分享,从多个方面讨论了在设计接口时遵循的原则,总共包含了七个大块.系卤煮自己总结的一些经验和教训.本篇博文同时也参考了其他一些文章,相关地址会在后面贴出来.很难做到 ...
- 一百元的智能家居——Asp.Net Mvc Api+讯飞语音+Android+Arduino
大半夜的,先说些废话提提神 如今智能家居已经不再停留在概念阶段,高大上的科技公司都已经推出了自己的部分或全套的智能家居解决方案,不过就目前的现状而言,大多还停留在展厅阶段,还没有广泛的推广起来,有人说 ...
- 在一个空ASP.NET Web项目上创建一个ASP.NET Web API 2.0应用
由于ASP.NET Web API具有与ASP.NET MVC类似的编程方式,再加上目前市面上专门介绍ASP.NET Web API 的书籍少之又少(我们看到的相关内容往往是某本介绍ASP.NET M ...
随机推荐
- I Love This Game 2115(结构体)
Problem Description Do you like playing basketball ? If you are , you may know the NBA Skills Challe ...
- stl之map容器的原理及应用
容器的数据结构同样是采用红黑树进行管理,插入的元素健位不允许重复,所使用的节点元素的比较函数,只对元素的健值进行比较,元素的各项数据可通过健值检索出来.map容器是一种关联容器,实现了SortedAs ...
- elasticsearch的rest搜索---mapping
目录: 一.针对这次装B 的解释 二.下载,安装插件elasticsearch-1.7.0 三.索引的mapping 四. 查询 五.对于相关度的大牛的文档 三.mapping 1. 索引的map ...
- iOS开发分析"秘密"App内容页面的效果(两)
@我前几天写的"秘密"的Cell制品的效果,想要的效果还是有差距,并且扩展性非常不好,于是重写封装,把总体视图都放到scrollView中,基本是和secret app 一模一样的 ...
- IOS SDK相机的详细解释/画廊(默认+他们的高清摄像头接口)
原版的blog,转载请注明出处 blog.csdn.net/hello_hwc 前言: 新NSURLSession的UploadTask的,结果写那个Demo的时候想要写成拍照上传.然后就想到先写一个 ...
- HTML5多图片拖拽上传带进度条
前言 昨天利用css2的clip属性实现了网页进度条觉得还不错,但是很多情况下,我们在那些时候用进度条呢,一般网页加载的时候如果有需要可以用,那么问题就来了,怎么才算整个加载完毕呢,是页面主要模块加载 ...
- autorun.vbs病毒的清除办法
症状:计算机里面出现一堆autorun为文件名称的文件,删除后出现找不到autorun.vbs的提示.我就打开当中的一个文件:Autorun.bat,内容例如以下: @echo off //不显示系 ...
- HDU 4873 ZCC Loves Intersection(可能性)
HDU 4873 ZCC Loves Intersection pid=4873" target="_blank" style="">题目链接 ...
- android 卸载程序、清除数据、停止服务用法
要实现卸载程序.清除数据.停止正在执行的服务这几大模块,如今将代码粗略总结例如以下: 主要运用到的类有 PackageManager ActivityManager ApplicationInfo R ...
- PLSQL_监控有些SQL的执行次数和频率
原文:PLSQL_监控有些SQL的执行次数和频率 2014-12-25 Created By 鲍新建