Synology Surveillance Web API 帮助。抢快照?
Synology Surveillance Web API Help. Grab Snapshot?
如何从 Surveillance Station Web API 获取 "snapshot"?我想做的是抓取快照并将其提供给网页。
不太熟悉 Web API 如何在 Synology Surveillance Station 上工作(我是编程方面的新手)。我试过阅读帮助。可在此处找到网络 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
这是身份验证问题吗?
API 的第 16 页说错误 105 是 "Insufficient user privilege"。按照第 14 页上显示的工作流程,您应该能够完成您想要的。尝试先调用登录方法(第 21 页),然后请求快照。
这可能会有所帮助:每当您看到 GET /webapi/...
时,您都可以将其更改为 http://MyNASip:5000/webapi/...
并使用您的浏览器发送请求。
获取快照的代码必须在访问快照之前从 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
代码很简单,大家可以随意寻找灵感
#!/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)
我知道这是一个旧线程,但我刚刚遇到了类似的问题并弄清楚了是怎么回事。 Surveillance Station 应用程序有自己的用户帐户,独立于 NAS 用户帐户。登录 Surveillance Station,并确保您在那里设置了用户。
如何从 Surveillance Station Web API 获取 "snapshot"?我想做的是抓取快照并将其提供给网页。
不太熟悉 Web API 如何在 Synology Surveillance Station 上工作(我是编程方面的新手)。我试过阅读帮助。可在此处找到网络 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
这是身份验证问题吗?
API 的第 16 页说错误 105 是 "Insufficient user privilege"。按照第 14 页上显示的工作流程,您应该能够完成您想要的。尝试先调用登录方法(第 21 页),然后请求快照。
这可能会有所帮助:每当您看到 GET /webapi/...
时,您都可以将其更改为 http://MyNASip:5000/webapi/...
并使用您的浏览器发送请求。
获取快照的代码必须在访问快照之前从 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
代码很简单,大家可以随意寻找灵感
#!/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)
我知道这是一个旧线程,但我刚刚遇到了类似的问题并弄清楚了是怎么回事。 Surveillance Station 应用程序有自己的用户帐户,独立于 NAS 用户帐户。登录 Surveillance Station,并确保您在那里设置了用户。