我在尝试下载附加到Podio项目的文件时遇到问题:
podio.request('get', '/file/{file_id}/raw').then(console.log);
Run Code Online (Sandbox Code Playgroud)
以上程序显示:
{}
Run Code Online (Sandbox Code Playgroud)
这是一个JSON字符串化的空对象(而不是原始文件内容).
细节:
file_id项目的图像字段时有效,但不能从文件附件(在我的情况下为pdf文件)中使用./item/app/{app_id}/filter获取项目列表时,属性file_count已设置,但不是files.我必须/item/{item_id}单独要求获得files包含在响应中的属性,不知道为什么.问题:您知道问题是什么,以及如何下载原始附件?
编辑:aditionnal信息
如果我使用以下命令请求单个文件元数据:
podio.request('get', '/file/1234').then(console.log);
Run Code Online (Sandbox Code Playgroud)
我得到一个文件JSON对象,其中包含许多字段,但不包含文件内容:
{
...
link: 'https://files.podio.com/1234',
file_id: 1234,
...
}
Run Code Online (Sandbox Code Playgroud)
正如我对@stengaard的评论中所述,如果我尝试为上述链接请求API,则响应如下:
{ [PodioNotFoundError: [object Object]]
message:
{ error_parameters: {},
error_detail: null,
error_propagate: false,
request:
{ url: 'http://api.podio.com/1234',
query_string: '',
method: 'GET' },
error_description: 'No matching operation could be found. The path \'/1234\' was not found..',
error: 'not_found' },
status: 404,
url: 'https://api.podio.com:443/1234',
name: 'PodioNotFoundError' }
Run Code Online (Sandbox Code Playgroud)
小智 5
要使用GET /file/{file_id}/raw端点,您需要具有提升的信任级别的API密钥.
而是使用GET /file/{file_id}端点.它包含link您应该遵循的属性(URL)以获取文件内容.
该link属性如下所示:https://files.podio.com/{file_id}.要获取文件吗https://files.podio.com/{file_id}?oauth_token={oauth_token}.OAuth令牌与以前的令牌相同GET /file/{file_id}.如果您知道文件ID(例如,GET /item/{item_id}您可以跳过GET /file/{file_id}并files.podio.com直接联系.(注意:Authorization: OAuth2 {oauth_token}如果您不喜欢在URL参数中传递身份验证令牌,也可以在HTTP请求中设置标头.)
有关如何使用它的示例,请参阅https://github.com/podio/podio-js/blob/master/lib/general.js#L11
通常在JS客户端中,如果您使用podioPodio API对象,OAuth令牌将位于那里:
podio.authObject.accessToken
Run Code Online (Sandbox Code Playgroud)
所以要在nodejs中获取文件的原始内容:
var url = 'https://files.podio.com/'+file_id+'?oauth_token='+podio.authObject.accessToken;
request(url, function (err, fileContent) {
// use fileContent here, write to a file, etc...
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
300 次 |
| 最近记录: |