簡體   English   中英

為什么 redirect_url 參數在我的 Vimeo ajax POST 上不起作用?

[英]Why doesn't the redirect_url parm work on my Vimeo ajax POST?

我在使用 Vimeo 上傳 API 將視頻從我們的網頁上傳到 Vimeo 時遇到問題,即使我已將正確的“接受”header 設置為版本 3.4,如 Vimeo 的 ZDB974278714CA8ACE4D634 頁面上指定的那樣。 任何人都可以建議為什么 redirect_url 參數不起作用? 其他一切正常並且視頻已上傳,但不會發生重定向。 這是我的完整頁面:

<!doctype html>
<html>
<head>

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link href="/include/jquerymmenu/jquery.mmenu.all.css" type="text/css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="application/javascript">
$.ajax({
        type: 'POST',
        url: 'https://api.vimeo.com/me/videos',
        upload: {
                approach: "post",
                redirect_url: 'https://www.example.com'
            },
        headers: {
             'Authorization': 'bearer ' + '<<my token here>>',
             'Content-Type': 'application/json',
             'Accept': 'application/vnd.vimeo.*+json;version=3.4'
           },
        
        success: function(res){
            console.log(res);
            // Write the form to the page
            $("div#myform").html(res.upload.form);
        },
        error: function(err){
            console.log(err);
        }
    });
</script>

<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div id="myform"></div>
</body>
</html>

在拉了很多頭發之后,我想出了一個解決方法來解決不支持 redirect_url 參數的 Vimeo POST 錯誤(他們的技術支持已經承認這是一個當前的錯誤)。

下面是完整的工作 php 頁面。 與 vimeo 示例不同,它實際上是 COMMENTED 和 COMPLETE!

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="robots" content="noindex, nofollow" />

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link href="/include/jquerymmenu/jquery.mmenu.all.css" type="text/css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script type="application/javascript">
//*************************************************************
// UPLOAD A VIDEO TO YOUR VIMEO ACCOUNT DIRECTLY FROM A WEB PAGE
// INCLUDING THE USE OF A REDIRECT_URL
//
// This is a hack of the Vimeo POST method of sending a video to Vimeo 
// since the Vimeo POST method has a bug which does not support the 
// redirect_url parameter.
//
// This page is completely self-contained. It makes an initial call
// to Vimeo in order to initialize the upload and displays the form
// returned from the initial call to the user, enabling them to 
// select their video and upload it. Following successful upload, 
// the user is redirected to the page they designate in sRedirectURL below
// along with any additional querystring parameters they wish to pass along
// to the target page (sAdditionalQuerystringParms).
//
//*************************************************************
// Define the redirect URL including the http or https prefix. such as https://example.com or http://example.com/folder/page.ext
var sRedirectURL = encodeURI('https://example.com');
// Define any additional querystring parameters STARTING WITH '&' (don't start with the usual '?')
// If there are no additional querystring parms, just set sAdditionalQuerystringParms = urlencode('');
// NOTE: We need to use the PHP urlencode instead of javascript encodeURI since javascript's encodeURI converts the 
// '&' to &amp; whereas the PHP urlencode converts '&' to the needed '%26'
var sAdditionalQuerystringParms = "<?php echo urlencode('&mytest=1');?>";

// Make the initial call to Vimeo which upon "success" will return a 'res' object containing the upload.form contents we need to display 
// the upload form to the user.
$.ajax({
        method: 'POST',
        url: 'https://api.vimeo.com/me/videos',
        upload: { 
            approach: "post"
           },
        headers: {
             'Authorization': 'bearer ' + '<<YOUR ACCESS TOKEN HERE>>',
             'Content-Type': 'application/json',
             'Accept': 'application/vnd.vimeo.*+json;version=3.4'
           },
        
        // Initial Vimeo call successful, now display the actual upload form to the user.
        success: function(res){
            console.log(res);
            // Write the form to the page
            $("div#myform").html(res.upload.form);
            
            // search the form's action= value and replace vimeo.com%2Fupload%2Fapi with the actual sRedirectURL 
            
            // fetch the current action
            var sAction = $("div#myform > form").attr("action");
            // search and replace the current redirect_url which VIMEO sets to itself, with our own redirect url
            var sNewAction = sAction.replace('https%3A%2F%2Fvimeo.com%2Fupload%2Fapi', sRedirectURL);
            // append any additional querystring parameters we wish to send to our redirect url besides the ones sent to our 
            // redirect from vimeo
            $("div#myform > form").attr("action",sNewAction + sAdditionalQuerystringParms);
            
            // At this point, the form is being displayed on the page and it's up to the user to select their video and press SUBMIT
            // to send their video to Vimeo.
        },
        error: function(err){
            console.log(err);
        }
    });
</script>

<title>Test Vimeo Upload</title>
</head>
<body>
<div id="myform"></div>
</body>
</html>

非常感謝您提供此解決方法。 有點懷疑這個大錯誤在幾個月后仍未修復。 我遇到了一個問題,我的名稱字段沒有保存為視頻的標題,我想知道它是否與 redirect_url 的問題類似。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM