Page 1 of 1

Not available to navigate to the page that has HTML component with codes

Posted: Fri Mar 13, 2015 1:00 pm
by Mark Wong

I have used the javascript and html to let users to upload videos to youtube.
However, when I try to navigate to that page at service success, its not available.
Image Image
You may want to check out the code in the html component (I've put the javascript together in the component)
code
<p><!doctype html>YouTube API Uploads</p>
<script type="text/javascript">/ <![CDATA[
/*
Copyright 2015 Google Inc&#46; All Rights Reserved&#46;

Licensed under the Apache License, Version 2&#46;0 (the "License");
you may not use this file except in compliance with the License&#46;
You may obtain a copy of the License at

http:&#47;&#47;www&#46;apache&#46;org/licenses/LICENSE-2&#46;0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied&#46;
See the License for the specific language governing permissions and
limitations under the License&#46;
*/

var signinCallback = function (result) {
if (result&#46;access_token) {
var uploadVideo = new UploadVideo();
uploadVideo&#46;ready(result&#46;access_token);
}
};

var STATUS_POLLING_INTERVAL_MILLIS = 60 * 1000; &#47;&#47; One minute&#46;

/**

  • YouTube video uploader class
    *

  • @constructor
    */
    var UploadVideo = function () {
    /**

    • The array of tags for the new YouTube video&#46;
      *

      • @attribute tags

      • @type Array&#46;<string>

      • @default ['google-cors-upload']
        */
        this&#46;tags = ['youtube-cors-upload'];

        /**

      • The numeric YouTube

      • [category id](https:&#47;&#47;developers&#46;google&#46;com/apis-explorer/#p/youtube/v3/youtube&#46;videoCategories&#46;list?part=snippetĀ®ionCode=us)&#46;
        *

      • @attribute categoryId

      • @type number

      • @default 22
        */
        this&#46;categoryId = 22;

        /**

      • The id of the new video&#46;
        *

      • @attribute videoId

      • @type string

      • @default ''
        */
        this&#46;videoId = '';

        this&#46;uploadStartTime = 0;
        };

    UploadVideo&#46;prototype&#46;ready = function (accessToken) {
    this&#46;accessToken = accessToken;
    this&#46;gapi = gapi;
    this&#46;authenticated = true;
    this&#46;gapi&#46;client&#46;request({
    path: '/youtube/v3/channels',
    params: {
    part: 'snippet',
    mine: true
    },
    callback: function (response) {
    if (response&#46;error) {
    console&#46;log(response&#46;error&#46;message);
    } else {
    $('#channel-name')&#46;text(response&#46;items[0]&#46;snippet&#46;title);
    $('#channel-thumbnail')&#46;attr('src', response&#46;items[0]&#46;snippet&#46;thumbnails&#46;
    default&#46;url);

    Code: Select all

             $('&#46;pre-sign-in')&#46;hide(); 
             $('&#46;post-sign-in')&#46;show(); 
         } 
     }&#46;bind(this) 

});
$('#button')&#46;on("click", this&#46;handleUploadClicked&#46;bind(this));
};

/**

  • Uploads a video file to YouTube&#46;
    *
  • @method uploadFile
  • @param {object} file File object corresponding to the video to upload&#46;
    */
    UploadVideo&#46;prototype&#46;uploadFile = function (file) {
    var metadata = {
    snippet: {
    title: $('#title')&#46;val(),
    description: $('#description')&#46;text(),
    tags: this&#46;tags,
    categoryId: this&#46;categoryId
    },
    status: {
    privacyStatus: $('#privacy-status option:selected')&#46;text()
    }
    };
    var uploader = new MediaUploader({
    baseUrl: 'https:&#47;&#47;www&#46;googleapis&#46;com/upload/youtube/v3/videos',
    file: file,
    token: this&#46;accessToken,
    metadata: metadata,
    params: {
    part: Object&#46;keys(metadata)&#46;join(',')
    },
    onError: function (data) {
    var message = data;
    &#47;&#47; Assuming the error is raised by the YouTube API, data will be
    &#47;&#47; a JSON string with error&#46;message set&#46; That may not be the
    &#47;&#47; only time onError will be raised, though&#46;
    try {
    var errorResponse = JSON&#46;parse(data);
    message = errorResponse&#46;error&#46;message;
    } finally {
    alert(message);
    }
    }&#46;bind(this),
    onProgress: function (data) {
    var currentTime = Date&#46;now();
    var bytesUploaded = data&#46;loaded;
    var totalBytes = data&#46;total;
    &#47;&#47; The times are in millis, so we need to divide by 1000 to get seconds&#46;
    var bytesPerSecond = bytesUploaded / ((currentTime - this&#46;uploadStartTime) / 1000);
    var estimatedSecondsRemaining = (totalBytes - bytesUploaded) / bytesPerSecond;
    var percentageComplete = (bytesUploaded * 100) / totalBytes;

    Code: Select all

         $('#upload-progress')&#46;attr({ 
             value: bytesUploaded, 
             max: totalBytes 
         }); 
    
         $('#percent-transferred')&#46;text(percentageComplete); 
         $('#bytes-transferred')&#46;text(bytesUploaded); 
         $('#total-bytes')&#46;text(totalBytes); 
    
         $('&#46;during-upload')&#46;show(); 
     }&#46;bind(this), 
     onComplete: function (data) { 
         var uploadResponse = JSON&#46;parse(data); 
         this&#46;videoId = uploadResponse&#46;id; 
         $('#video-id')&#46;text(this&#46;videoId); 
         $('&#46;post-upload')&#46;show(); 
         this&#46;pollForVideoStatus(); 
     }&#46;bind(this) 

});
&#47;&#47; This won't correspond to the exact start of the upload, but it should be close enough&#46;
this&#46;uploadStartTime = Date&#46;now();
uploader&#46;upload();
};

UploadVideo&#46;prototype&#46;handleUploadClicked = function () {
$('#button')&#46;attr('disabled', true);
this&#46;uploadFile($('#file')&#46;get(0)&#46;files[0]);
};

UploadVideo&#46;prototype&#46;pollForVideoStatus = function () {
this&#46;gapi&#46;client&#46;request({
path: '/youtube/v3/videos',
params: {
part: 'status,player',
id: this&#46;videoId
},
callback: function (response) {
if (response&#46;error) {
&#47;&#47; The status polling failed&#46;
console&#46;log(response&#46;error&#46;message);
setTimeout(this&#46;pollForVideoStatus&#46;bind(this), STATUS_POLLING_INTERVAL_MILLIS);
} else {
var uploadStatus = response&#46;items[0]&#46;status&#46;uploadStatus;
switch (uploadStatus) {
&#47;&#47; This is a non-final status, so we need to poll again&#46;
case 'uploaded':
$('#post-upload-status')&#46;append('<li>Upload status: ' + uploadStatus + '</li>');
setTimeout(this&#46;pollForVideoStatus&#46;bind(this), STATUS_POLLING_INTERVAL_MILLIS);
break;
&#47;&#47; The video was successfully transcoded and is available&#46;
case 'processed':
$('#player')&#46;append(response&#46;items[0]&#46;player&#46;embedHtml);
$('#post-upload-status')&#46;append('<li>Final status&#46;</li>');
break;
&#47;&#47; All other statuses indicate a permanent transcoding failure&#46;
default:
$('#post-upload-status')&#46;append('<li>Transcoding failed&#46;</li>');
break;
}
}
}&#46;bind(this)
});
};

&#47;&#47; ]]></script>
<p><span id="signinButton" class="pre-sign-in"> <!-- IMPORTANT: Replace the value of the <code>data-clientid
attribute in the following tag with your project's client ID&#46; --> </span></p>
<div class="post-sign-in">
<div><img id="channel-thumbnail" alt="" /> <span id="channel-name"></span><>
<div><label for="title">Title:</label> <input id="title" type="text" value="Default Title" /><>
<div><label for="description">Description:</label> <textarea id="description">Default description</textarea><>
<div><label for="privacy-status">Privacy Status:</label><select id="privacy-status">
<option>public</option>
<option>unlisted</option>
<option>private</option>
</select><>
<div><input id="file" class="button" type="file" accept="video/*" /> <button id="button">Upload Video</button>
<div class="during-upload">
<p><span id="percent-transferred"></span>% done (<span id="bytes-transferred"></span>/<span id="total-bytes"></span> bytes)</p>
<>
<div class="post-upload">
<p>Uploaded video with id <span id="video-id"></span>&#46; Polling for status&#46;&#46;&#46;</p>
<ul id="post-upload-status"></ul>
<div id="player">&nbsp;<>
<>
<p id="disclaimer">By uploading a video, you certify that you own all rights to the content or that you are authorized by the owner to make the content publicly available on YouTube, and that it otherwise complies with the YouTube Terms of Service located at <a href="http:&#47;&#47;www&#46;youtube&#46;com/t/terms" target="_blank">http:&#47;&#47;www&#46;youtube&#46;com/t/terms</a></p>
<>
<script type="text/javascript" src="http:&#47;&#47;ajax&#46;googleapis&#46;com/ajax/libs/jquery/1&#46;10&#46;2/jquery&#46;min&#46;js"></script>
<script type="text/javascript" src="http:&#47;&#47;apis&#46;google&#46;com/js/client:plusone&#46;js"></script>
<script type="text/javascript" src="cors_upload&#46;js"></script>
<script type="text/javascript" src="upload_video&#46;js"></script>
<>
/code


Not available to navigate to the page that has HTML component with codes

Posted: Fri Mar 13, 2015 2:33 pm
by Illya Stepanov

Hi -

[quote:]
However, when I try to navigate to that page at service success, its not available.
[/quote]

Please describe this process with more details, navigate to what page from where?


Not available to navigate to the page that has HTML component with codes

Posted: Fri Mar 13, 2015 7:52 pm
by Mark Wong

Sorry,
there were mistakes in the html, now everything works probably except:
Image Image
code
var uploader = new MediaUploader({
baseUrl: 'https:&#47;&#47;www&#46;googleapis&#46;com/upload/youtube/v3/videos',
file: file,
token: this&#46;accessToken,
metadata: metadata,
params: {
part: Object&#46;keys(metadata)&#46;join(',')
},
onError: function(data) {
var message = data;
&#47;&#47; Assuming the error is raised by the YouTube API, data will be
&#47;&#47; a JSON string with error&#46;message set&#46; That may not be the
&#47;&#47; only time onError will be raised, though&#46;
try {
var errorResponse = JSON&#46;parse(data);
message = errorResponse&#46;error&#46;message;
} finally {
alert(message);
}
}/code
You may need this.
So the problem is that when I try to upload videos through this, the error of define MediaUploader happens


Not available to navigate to the page that has HTML component with codes

Posted: Mon Mar 16, 2015 10:32 am
by Egor Kotov6832188

Hello Mark,
before MediaUploader you have 4 errors, which based on mistakes in your custom js code.


Not available to navigate to the page that has HTML component with codes

Posted: Mon Mar 16, 2015 2:43 pm
by Mark Wong

Image
I've tried my best to fix all the errors.
The 1st and 2nd errors (JS) appeared when I click execute service button (After I upload video to Youtube)
3rd error appear when I tried to press back button at the upload page
Are these errors occur because the XMLHttpRequest Warning?


Not available to navigate to the page that has HTML component with codes

Posted: Mon Mar 16, 2015 3:57 pm
by Mark Wong

Thank you for your efforts!
I've already solved this problem!