将访问令牌与SkyDrive API一起使用

时间:2014-01-16 09:13:43

标签: api access-token onedrive

我一直试图通过以下链接访问json结果:

  

https://apis.live.net/v5.0/file.a4423f3123801749.A4423F3123801749!418

但正如您自己点击它所看到的那样,您需要一个访问令牌。 我已经有一个访问令牌,但它只持续3600秒(1小时)。

有没有办法在没有访问令牌到期的情况下获取链接的结果(如下所示的json)?我知道有一个刷新令牌,但我不确定如何使用它。

{
   "id": "file.a4423f3123801749.A4423F3123801749!418", 
   "from": {
      "name": "Andrew Wong", 
      "id": "a4423f3123801749"
   }, 
   "name": "Mod Permissions.xlsx", 
   "description": "", 
   "parent_id": "folder.a4423f3123801749.A4423F3123801749!129", 
   "size": 89956, 
   "upload_location": "https://apis.live.net/v5.0/file.a4423f3123801749.A4423F3123801749!418/content/", 
   "comments_count": 0, 
   "comments_enabled": true, 
   "is_embeddable": true, 
   "source": "https://hvbqwg.dm2302.livefilestore.com/y2m6t-kEOaAd1qXi2n4cvNuVCMqU2Is3Ft_7g7UGM1h6Ib8oyGSFzT70rT3F3mz5PFsrzUDkyAfhYoh1YIZWNY3INmCIKheJpZWoUVTvz-xh5I/Mod%20Permissions.xlsx?psid=1", 
   "link": "https://skydrive.live.com/redir.aspx?cid=a4423f3123801749&page=view&resid=A4423F3123801749!418&parid=A4423F3123801749!129", 
   "type": "file", 
   "shared_with": {
      "access": "Public"
   }, 
   "created_time": "2014-01-16T07:06:41+0000", 
   "updated_time": "2014-01-16T07:14:51+0000", 
   "client_updated_time": "2014-01-16T07:14:51+0000"
}

1 个答案:

答案 0 :(得分:0)

发布https://login.live.com/oauth20_token.srf帖子,将refresh_token转换为access_token。阅读MS documentation项目符号#6中的更多信息。

以下是node.js代码示例

var options,request;
request = require('request');

options = {
  url: 'https://login.live.com/oauth20_token.srf',
  form: {
    client_id: YOUR CLIENT_ID,
    redirect_uri: YOUR REDIRECT_URI,
    client_secret: YOUR CLIENT_SECRET,
    refresh_token: YOUR REFRESH_TOKEN,
    grant_type: 'refresh_token'
  },
  headers: {
    'Accept': 'application/json'
  }
};

request.post(options, function(err, response, data) {
});