Synology Surveillance Web API帮助。抢快照?

问题描述 投票:1回答:4

如何从Surveillance Station Web API获取“快照”?我想要做的是获取快照并将其提供给网页。

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

当我将其输入浏览器时,我希望能够获得快照JPG

http://MyNASip:5000/webapi/entry.cgi?camStm=1&version="8"&cameraId=1&api="SYNO.SurveillanceStation.Camera"&preview=true&method="GetSnapshot"

我明白了吗?

相反,我在浏览器中得到了这个

{"error":{"code":105},"success":false}

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

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

是身份验证问题吗?

json http synology
4个回答
0
投票

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

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


1
投票

获取快照的代码必须在访问快照之前从api获取PATH,CAMERA PATH和SID。这是我的代码的摘录(见下文)

$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 Station API的所有调用。你可以抓住快照,mjpeg,开始停止,发送邮件等。

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

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


0
投票
#!/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)

0
投票

我意识到这是一个老线程,但我只是遇到了类似的问题,并弄清楚发生了什么。 Surveillance Station应用程序有自己的用户帐户,与NAS用户帐户分开。登录Surveillance Station,确保在那里设置了用户。

© www.soinside.com 2019 - 2024. All rights reserved.