Saturday, 17 August 2013

Youtube API rate Authentication issue

Youtube API rate Authentication issue

I'm using javascript to send Authentication to google and than using the
returned access_token to add a like to a specific video, however i always
get the following response - code: 401,message: "Login Required" this is
my html code after successful auth: Thanks in advance - Ron
<!DOCTYPE html>
<html>
<head>
<title>Youtube page</title>
<script
src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="auth.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="login-container" class="pre-auth">This application
requires access to your YouTube account.
Please <a href="#" id="login-link">authorize</a> to continue.
</div>
<div><button id="button-like">Like</button></div>
<div id ="result"></div>
<script
src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="auth.js"></script>
<script
src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script>
<script>
$('#button-like').click(function() {
var id = "rbJtIDFwFXQ";
var rating = "like"
var tokenKey = $('#result').text();
var key = '********';
// Do a post to the server to finish the logon
// This is a form post since we don't want to use AJAX
var form = document.createElement("form");
form.setAttribute("method", 'post');
form.setAttribute("action",
'https://www.googleapis.com/youtube/v3/videos/rate');
var field = document.createElement("input");
field.setAttribute("type", "hidden");
field.setAttribute("id", id);
field.setAttribute("rating", rating);
field.setAttribute("access_token", tokenKey);
field.setAttribute("key", key);
form.appendChild(field);
document.body.appendChild(form);
form.submit();
});
</script>
</body>
</html>

No comments:

Post a Comment