首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Synology Surveillance API帮助。抓取快照?

Synology Surveillance API帮助。抓取快照?
EN

Stack Overflow用户
提问于 2018-02-06 03:26:52
回答 4查看 4.3K关注 0票数 2

如何从监控站Web API抓取“快照”?我想要做的是抓取一个快照,并将其提供给一个网页。

对Synology Surveillance的Web API如何工作不是很熟悉(我一般是编程新手)。我试着通读帮助。可以在此处找到web API帮助。Surveillance Station Web API

当我在浏览器中输入这段代码时,我希望得到一个快照JPG

代码语言:javascript
复制
http://MyNASip:5000/webapi/entry.cgi?camStm=1&version="8"&cameraId=1&api="SYNO.SurveillanceStation.Camera"&preview=true&method="GetSnapshot"

我的理解对吗?

取而代之的是,我在浏览器中得到了这个

代码语言:javascript
复制
{"error":{"code":105},"success":false}

我在/var/log/messages中得到了以下内容

代码语言:javascript
复制
2018-02-05T13:15:03-06:00 DS215j synoscgi_SYNO.SurveillanceStation.Camera_8_GetSnapshot[15020]: group_is_admin_group_member_by_uid.c:14 SYNOUserGetByUID(4294967295) failed [0x1D00 user_get_by_uid.c:129

是否存在身份验证问题?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2018-02-06 04:39:06

API的第16页显示错误105是“用户权限不足”。按照第14页所示的工作流程,您应该能够完成您想要的工作。首先尝试调用登录方法(第21页),然后请求快照。

这可能会有所帮助:每当您看到GET /webapi/...时,都可以将其更改为http://MyNASip:5000/webapi/...并使用浏览器发送请求。

票数 1
EN

Stack Overflow用户

发布于 2018-09-18 22:13:53

抓取快照的代码必须先从api获取路径、摄像头路径和SID,然后才能访问快照。下面是我的代码的摘录(如下所示)

代码语言:javascript
复制
$user = "xxxxxxx";  // Synology username with rights to Surveillance station 
$pass = "xxxxxxx";  // Password of the user entered above 
$ip = "192.168.xxxxxx";  // IP-Adress of your Synology-NAS 
$port = "5000";  // default port of Surveillance Station 
$http = "http"; // Change to https if you use a secure connection 
$cameraID = xx;
$cameraStream = xx];
$vCamera = 7; //Version API SYNO.SurveillanceStation.Camera
$vAuth = ""; 
if ($cameraStream == NULL) { 
    $cameraStream = "0"; 
} 
//Get SYNO.API.Auth Path (recommended by Synology for further update)
    $json = file_get_contents($http.'://'.$ip.':'.$port.'/webapi/query.cgi?api=SYNO.API.Info&method=Query&version=1&query=SYNO.API.Auth');
    $obj = json_decode($json);
    $AuthPath = $obj->data->{'SYNO.API.Auth'}->path;
// Authenticate with Synology Surveillance Station WebAPI and get our SID 
    $json = file_get_contents($http.'://'.$ip.':'.$port.'/webapi/'.$AuthPath.'?api=SYNO.API.Auth&method=Login&version=6&account='.$user.'&passwd='.$pass.'&session=SurveillanceStation&format=sid'); 
    $obj = json_decode($json); 
//Check if auth ok
if($obj->success != "true"){
    echo "error";
    exit();
}else{
//authentification successful
    $sid = $obj->data->sid;

//Get SYNO.SurveillanceStation.Camera path (recommended by Synology for further update)
        $json = file_get_contents($http.'://'.$ip.':'.$port.'/webapi/query.cgi?api=SYNO.API.Info&method=Query&version=1&query=SYNO.SurveillanceStation.Camera');
        $obj = json_decode($json);
        $CamPath = $obj->data->{'SYNO.SurveillanceStation.Camera'}->path;

// Get Snapshot
if ($cameraID != NULL) { 
        // Setting the correct header so the PHP file will be recognised as a JPEG file 
        header('Content-Type: image/jpeg'); 
        // Read the contents of the snapshot and output it directly without putting it in memory first 
        readfile($http.'://'.$ip.':'.$port.'/webapi/'.$CamPath.'?camStm='.$cameraStream.'&version='.$vCamera.'&cameraId='.$cameraID.'&api=SYNO.SurveillanceStation.Camera&preview=true&method=GetSnapshot&_sid='.$sid); 
}

这是我编写的php脚本的摘录,用于将所有调用连接到synology Surveillance API。你可以抓取快照,mjpeg,开始,停止,发送邮件等。

这就是:https://github.com/sjauquet/YAPUSS

代码非常简单,请随意寻找灵感。

票数 3
EN

Stack Overflow用户

发布于 2019-03-11 18:29:22

代码语言:javascript
复制
#!/usr/bin/python
import cookielib, urllib2

cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
nas =  'url.synology.me'
dsm_url = 'https://'+nas+':8080'
username = 'user'
password = 'password'

opener.addheaders = [
        ('User-Agent', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11'),
            ]
url1=dsm_url+'/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=1&account='+username+'&passwd='+password+'&session=SurveillanceStation&format=sid'
url3=dsm_url+'/webapi/entry.cgi?api=SYNO.SurveillanceStation.Camera&method=GetSnapshot&version=1&cameraId=2&preview=true'
url4=dsm_url+'/webapi/auth.cgi?api=SYNO.API.Auth&method=Logout&version=1&account='+username+'&passwd='+password+'&session=SurveillanceStation'

opener.open(url1)

stream=opener.open(url3)
with open ('image.jpg','w') as f1: f1.write(stream.read())
opener.open(url4)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48630033

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档