Skip to content

Instantly share code, notes, and snippets.

@oshikryu
Created April 30, 2013 20:44
Show Gist options
  • Save oshikryu/5491807 to your computer and use it in GitHub Desktop.
Save oshikryu/5491807 to your computer and use it in GitHub Desktop.
youtube player facebook watch posting
// handle the facebook api watch functions for the youtube player
// removes the posted watch if it does not meet the requirements
var ytPlayerInterval, ytplayer;
function handleAPIWatch(){
try {
($('#modal_content object embed')[0]) ? ytplayer = $('#modal_content object embed')[0] : ytplayer = "";
var time = ytplayer.getCurrentTime();
if(ytplayer.getCurrentTime() >= (ytplayer.getDuration() / 2)) {
// console.log("out after 50");
if (fbstart) {
FB.api(
'/'+ actionID,
'post',
{expires_in : ytplayer.getDuration() },
function (response) {
console.log(response);
}
);
}
clearInterval(ytPlayerInterval);
}
else {
// console.log("out before 50");
if (fbstart) {
removeWatchAction(actionID);
}
clearInterval(ytPlayerInterval);
}
} catch(e) {
//whatever
clearInterval(ytPlayerInterval);
}
}
// remove watch
function removeWatchAction(id) {
$('#fb_disclaimer').html('Removing video view posted to your Facebook.');
FB.api(
'/'+ id,
'delete',
function (response) {
// console.log(response);
$('#fb_disclaimer').html('Removing video view completed.');
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment