MattTW / BlinkMonitorProtocol

Unofficial documentation for the Blink Wire-Free HD Home Monitoring & Alert System
443 stars 82 forks source link

/api/v2/accounts/XXX/media/clip/ no longer working (401. Unauthorized) #53

Closed dejarikbcn closed 3 years ago

dejarikbcn commented 3 years ago

I recently noticed that the download clip service stopped working, and now I'm always receiving 401. Unauthorized response codes.

This behavior began 3 o 4 days ago.

I'm still able to retrieve the clip list with this call (includig a proper TOKEN_AUTH header):

https://rest-e002.immedia-semi.com/api/v1/accounts/XXXX/media/changed?since=2021-02-19T12:31:00+0000&page=1

Which returns the JSON's available clips list:

{
...
"media": [
        {
            "id": XXX,
            "created_at": "2021-02-19T13:31:43+00:00",
            "updated_at": "2021-02-19T15:54:18+00:00",
            "deleted": false,
            "device": "camera",
            "device_id": XXX,
            "device_name": "XXX",
            "network_id": XXX,
            "network_name": "XXX",
            "type": "video",
            "source": "pir",
            "watched": true,
            "partial": false,
            "thumbnail": "/api/v2/accounts/XXX/media/thumb/XXX",
            "media": "/api/v2/accounts/XXX/media/clip/XXX.mp4",
            "additional_devices": [],
            "time_zone": "Europe/Madrid"
        }
    ]
...
}

However, the download call is no longer working (no changes in my code were made for weeks...)

https://rest-e002.immedia-semi.com/api/v2/accounts/XXX/media/clip/XXX.mp4

Always receiving:

{
    "message": "Unauthorized Access",
    "code": 101
}

Is anybody experiencing the same issue?

Thank you!

Best regards

becomingmountains commented 3 years ago

Yeah I am experiencing the same issue. Any update on this?

ZaGaPonG commented 3 years ago

Hi,

FIY, I'm accessing to API via a custom scripting in LUA, example for getting the last thumbnail (i'm not developer, sorry if not optimized) :

function savePicture(blink_auth_token, blink_camera_filename, blink_camera_id)
    -- Récupération des infos du system Blink
    local blink_infos = assert(io.popen('curl -H "Host: '..blink_host..'" -H "TOKEN_AUTH: '..blink_auth_token..'" --compressed https://'..blink_host..'/network/'..blink_network_id..'/camera/'..blink_camera_id, 'r'))
    local blink_infos_response = assert(blink_infos:read('*a'))
    blink_infos:close()
    local jsonData = json:decode(blink_infos_response)
    local thumbnail_url = json:encode_pretty(jsonData['camera_status']['thumbnail'])

    -- Horodatage et stockage de la capture sur le NAS
    os.execute("curl -H 'Host: "..blink_host.."' -H 'TOKEN_AUTH: "..blink_auth_token.."' --compressed https://"..blink_host..""..thumbnail_url..".jpg > /volume1/web/camera/blink/`/bin/date '+%Y-%m-%d_%H-%M-%S'`-"..blink_camera_filename..".jpg")

And facing the same issue since 2 days (last run OK: 2021-03-10_15-17-19 - GMT+2).

becomingmountains commented 3 years ago

I'm guessing at this point that Blink has made that endpoint obsolete or restricted access. It's too bad. Seems to be the only way to get actual video from the API.

usmcBowden commented 3 years ago

I found a solution to this problem that allowed me to download a clip. I was able to send a request and convert the mp4 to a byte[] array

Its in c#, but here is the method in my utilities class.

public async Task<byte[]> GetClipAsync(String url, String token)
        {
            byte[] response;
            using (var httpClient = new HttpClient())
            {

                using (var request = new HttpRequestMessage(new HttpMethod("GET"), Properties.Settings.Default.RegionAPI + url))
                {
                    request.Headers.TryAddWithoutValidation("token-auth", token);
                    HttpContent content = httpClient.SendAsync(request).Result.Content;
                    response = await content.ReadAsByteArrayAsync();
                }
            }
            return response;
        }

I return then returned the response to my form and saved the file to my computer like so...

uri is the path to the mp4 provided by the API. Once the file is written I open a new form with a media player object and play the clip.

private async void ClipView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int rowIndex = e.RowIndex;
            String uri = ClipView.Rows[rowIndex].Tag.ToString();
            String fileName = Path.GetFileName(uri);
            byte[] mp4 = await Blink.GetClipAsync(uri, user.getToken());
            String path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            String pathString = System.IO.Path.Combine(path, "Blink Desktop");
            String filePathString = System.IO.Path.Combine(pathString, fileName);
            if (!System.IO.Directory.Exists(pathString))
                System.IO.Directory.CreateDirectory(pathString);
            if (!System.IO.File.Exists(filePathString))           
                File.WriteAllBytes(filePathString, mp4);

            Properties.Settings.Default.currentClipSelection = filePathString;
            var ClipPlayer = new Clip_Player();
            ClipPlayer.Show();
        }

I found an issue with what I posted. I realized I didn't test enough and after I download 2-7 videos I start getting corrupted downloads. However, when opened in notepad it's a cloudflare error. Trying to find out how to avoid it.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Request blocked.
We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: 1PSfUq8j-aka01L1F_079Fe0FjU5pUgErxUHUDX0dfanaKsqFqCFMg==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>
dejarikbcn commented 3 years ago

I noticed that I need to upgrade my login function to use "v5" API.

After that migration, everything worked fine again.

Sorry for the misleading focus of this issue.