如何从Google Glass项目中提取附件? [英] How to pull attachments from Google Glass item?
问题描述
我创建了与Google Glass通信的NodeJS服务器,我想知道如何从项目中提取附件,下面您可以看到带有附件的项目:
注意:在我的项目中,我已经有:
*将项目项发送到玻璃(联系人,卡片,位置等).
*订阅时间轴集合
*与回调联系以让Glass用户共享内容-有关更多信息,请访问解决方案
selfLink
引用timelineItem本身的URL.您要查看对象的attachments
属性.它可能看起来像这样:
{ "kind": "mirror#timelineItem",
"id": "da61598c-2890-4852-2123-031011dfa004",
...
"attachments": [
"id": ...
"contentType": "image/jpeg".
"contentUrl": "https://www.googleapis.com/mirror/v1/timeline/da61598c-2890-4852-2123-031011dfa004/attachments/ps:605507433604363824",
"isProcessingContent": false
]
}
在尝试获取isProcessingContent
之前,应检查以确保isProcessingContent
为假,否则获取将失败.通常对于图像来说这是相当快的,但是对于视频来说可能花费更长的时间.
在 https://developers.google.com/glass/v1上了解更多信息. /reference/timeline/attachments
要获取它,您可以使用值为Bearer auth_token
的Authorization
标头向该URL发出HTTPS请求(将auth_token替换为auth令牌的实际值).
要发出请求本身,您可能需要使用http.request()
方法.所以像这样(未经测试)可能会起作用:
var item = {the item you got sent above};
var attachment = item.attachments[0];
if( !attachment.isProcessingContent ){
var contentUrl = url.parse( attachment.contentUrl );
var options = {
"hostname": contentUrl.hostname,
"path": contentUrl.path,
"headers": {
"Authorization": 'Bearer '+authToken;
}
}
https.request( options, function(res){
// Get the image from the res object
});
}
请参阅 URL.parse 和 HTTPS.request .
I created NodeJS server that communicate with Google Glass, I want to know how to pull attachment from item, below you can see the item with attachments:
Note: in my project I already have:
*Send item item to glass(contact, card, location, etc..)
*Subscription to timeline collection
*Contact with callback to let Glass user share content - for more info Visit How to add another option to the share functionality of Google Glass?
Do I need to use the selfLink to pull the attachment? if yes then how I can execute HTTP request for the selfLink while including the token?
The selfLink
refers to the URL of the timelineItem itself. You want to look at the attachments
attribute of the object. It might look something like this:
{ "kind": "mirror#timelineItem",
"id": "da61598c-2890-4852-2123-031011dfa004",
...
"attachments": [
"id": ...
"contentType": "image/jpeg".
"contentUrl": "https://www.googleapis.com/mirror/v1/timeline/da61598c-2890-4852-2123-031011dfa004/attachments/ps:605507433604363824",
"isProcessingContent": false
]
}
You should check to make sure isProcessingContent
is false before you try to fetch it, otherwise the fetch will fail. This is usually pretty quick for images, but can take longer for video.
See more at https://developers.google.com/glass/v1/reference/timeline/attachments
To fetch it, you can issue an HTTPS request to that URL with an Authorization
header with a value of Bearer auth_token
(replacing auth_token with the actual value of the auth token).
To make the request itself, you'll probably want to use the http.request()
method. So something like this (untested) might work:
var item = {the item you got sent above};
var attachment = item.attachments[0];
if( !attachment.isProcessingContent ){
var contentUrl = url.parse( attachment.contentUrl );
var options = {
"hostname": contentUrl.hostname,
"path": contentUrl.path,
"headers": {
"Authorization": 'Bearer '+authToken;
}
}
https.request( options, function(res){
// Get the image from the res object
});
}
See the documentation for URL.parse and HTTPS.request for details.
这篇关于如何从Google Glass项目中提取附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!