2017-03-01 117 views
0

我需要創建一個正則表達式來驗證有效的Vimeo視頻。如何驗證Vimeo視頻ID?

根據Vimeo API,它們只使用Video Id的數字,但它們沒有指定長度。

我的正則表達式到目前爲止var regEx= /^[0-9]+$/;

我想知道: - 什麼是允許的長度由VIMEO視頻ID的支持? - 如何修改我的regEx?

只有文章中,我發現: https://vimeo.com/forums/topic:267078

+1

試圖讓幾個ID,以查看是否有規律可循的。如果有的話,然後優化你的正則表達式。如果沒有,那麼我可以考慮的唯一方法就是使用HTTP請求來查看視頻是否在響應中的某處返回。 – Potray

回答

2

而不是試圖創造一種Vimeo的視頻ID驗證,你爲什麼不只是使用Vimeo developper API來檢查Vimeo的ID是有效的?

GET https://api.vimeo.com/videos/{video_id} 

+------------------+--------------------------------------------------+ 
| Http Status Code | Explanation          | 
+------------------+--------------------------------------------------+ 
| 200 Ok   |             | 
+------------------+--------------------------------------------------+ 
| 403    | if the video does exist, but the view or the app | 
|     | requesting the video resource does not have  | 
|     | permission to access that video.     | 
+------------------+--------------------------------------------------+ 
| 404 not found | If the video cannot be found.     | 
+------------------+--------------------------------------------------+ 

檢查,如果你(1)或用戶(2)擁有視頻:

(1) GET https://api.vimeo.com/me/videos/{video_id} 
(2) GET https://api.vimeo.com/users/{user_id}/videos/{video_id} 

+------------------+------------------------------------------------------+ 
| Http Status Code | Explanation           | 
+------------------+------------------------------------------------------+ 
| 200 Ok   |              | 
+------------------+------------------------------------------------------+ 
| 404 not found | If the video is not owned by the authenticated user. | 
+------------------+------------------------------------------------------+ 
+1

另外值得注意的是,如果視頻_does_存在,API將返回403,但請求視頻資源的查看器或應用無權訪問該視頻。例如:密碼保護的視頻。 –

+1

密碼保護的視頻爲我獲得400。 –