MyDlink-API-Python icon indicating copy to clipboard operation
MyDlink-API-Python copied to clipboard

Help: privacy control and PTZ setting

Open Goufalite opened this issue 3 years ago • 5 comments

Hello and thanks for this good start for querying/setting data on Dlink cameras

I'm trying to modify the code to fetch the privacy settings and eventually set the PTZ. I was able to see which function was called by F12-ing the mydlink.com website and playing a little with controls.

First of all, I'm able to log in and get my camera standard info (device list and device info) with no problem thanks to the provided example. But when I call the control function I get a privilege error...

{'error': {'message': 'Client doesnt have privilege.', 'code': 31}}

I've found that to control and get the privacy settings and even play with PTZ, the entry point is

POST /v2/device/control?acces_token=ACCESSTOKEN

(note the v2, if I put me in place I get another same error {'error': {'message': 'Client doesnt have privilege.', 'code': 31, 'type': 'Device'}})

And then embed the JSON to the POST body to query the info

{"data":{"mydlink_id":"1234","uid":0,"idx":0,"ctrl_id":513}}

Or add a value to set the privacy

{"data": {"mydlink_id": "1234", "uid": 0, "idx": 0, "ctrl_id": 513, "value": {"value": 2}}}

Or PTZ

{"data": {"mydlink_id": "1234", "uid": 0, "idx": 0, "ctrl_id": 26, "value": {"p": 165, "t": 12, "z": 0}}}

Unfortuately I'm getting the error above, and not when I query the device list and info...

I'm SOOOO close of finding this, if you find anything that might help me a little thank you in advance!

Example of implementation of the get privacy function

def get_device_privacy(self, mydlink_id:str) -> json:
	device_privacy_url = "https://{openapi}/v2/device/control?access_token={access_token}".format(
		openapi=self.login_params.get('api_site')[0],
		access_token=self.login_params.get('access_token')[0]
	)
			
	json_object = {}
	json_object['mydlink_id'] = mydlink_id
	json_object['uid'] = 0
	json_object['idx'] = 0
	json_object['ctrl_id'] = 513

	json_object_final = {}
	json_object_final['data'] = json_object
			
	response = self.url_utils.get_request(url=device_privacy_url, type=self.url_utils.TYPE_POST,
										  input_json=json_object_final)

	device_privacy_json = Url.parse(response.content.decode('utf8'))
	print(device_privacy_json)
	return device_privacy_json['data']

Goufalite avatar Jul 18 '21 22:07 Goufalite

Hello Goufalite, thank you for working on it. I have already come across this case and have found that the setting of device settings is not via the URL by post (seems to be historical or something like my assumption) but the stream from the camera and settings are set via socket connection, but there Unfortunately I don't get any further

ageof avatar Sep 07 '21 11:09 ageof

@Goufalite Where do you find the /v2/device/control url out ?

ageof avatar Sep 08 '21 13:09 ageof

By watching the network on mydlink.com sometimes there's v2 sometimes there's me.

I don't see any websocket communication in the network view of chrome...

Goufalite avatar Sep 08 '21 21:09 Goufalite

Thanks for the info that you can see the cloud camera on mydlink.com is new, that has probably changed since the last update. Before you could only address and use the devices via the app and the app uses sockets in some places. I'll have a look at setting the private settings later, probably just something missing in the header of the request

ageof avatar Sep 09 '21 05:09 ageof

@Goufalite Found the reason for your error message. This is because the wrong token is being used for this interface.

ageof avatar Sep 10 '21 12:09 ageof