Created
April 30, 2013 20:44
-
-
Save oshikryu/5491807 to your computer and use it in GitHub Desktop.
youtube player facebook watch posting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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