Facebook instant games api method canSubscribeBotAsync method is not a function - facebook

So my game wants the players to have the ability to subscribe to a game bot and I'm using FBInstant.player.canSubscribeBotAsync() method. But everytime, it will return an error that state
Uncaught TypeError: FBInstant.player.canSubscribeBotAsync is not a function
here is my code
FBInstant.player.canSubscribeBotAsync().then(function(yes){
if(yes){
FBInstant.player.subscribeBotAsync().then(function(){
console.log('sub');
}).catch(function(e)){}
}
});
I tried using this code from FB developer doc
FBInstant.player.canSubscribeBotAsync().then(
can_subscribe => console.log(can_subscribe)
);
but the result still the same.

It seems that I tried to let the player subscribe when they click the button and this error appears.
But when I switch it from letting the player click the subscribe button to asked when player finished loading the game, the error disappears. The program's flow look like this
window.onload = async () => {
FBInstant.initializeAsync().then(()=>{
FBInstant.startGameAsync().then((res)=>{
FBInstant.player.canSubscribeBotAsync().then((canSub)=>{
//Ask for sub or something
}).catch(()=>console.log("Error"))
})
})
But for me, this is a temporary fix since normally you should be able to call a function anywhere you want (working or not isn't my problem) and my problem is that I can only call FBInstant.player.canSubscribeBotAsync() inside FBInstant.initializeAsync() or FBInstant.startGameAsync() but not outside of them

Related

Unity WebGL OnApplicationQuit()?

I need to remove player from database when he closes tab with WebGL game. I tried using OnApplicationQuit(), but that does not fire. Is there something similar that can be used for WebGL to call some logic when player closes the tab?
For anyone else who might struggle with this I solved it in a following way:
Inside WebGL template index.html i added this code ( SendMessage - https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html )
window.onbeforeunload = () => {
unityInstance.SendMessage("CloseEvent", "CloseCallback");
return "Are you sure to leave this page?";
}
in my case I put this code inside <script> after this code ( that's where unityInstance is assigned from above )
script.onload = () => {
createUnityInstance
....
Important part for me was to have the return there, which shows alert window. That allows me to call database and make changes. Without the alert window the db call does not go through for some reason. Btw you can't change the text of the alert window unfortunately because of browser security changes.
Hope this helps someone else in the future. Spent full day on this.

Post picture on Facebook wit Actionscript3 Graph API

I want to upload a picture from as3 to Facebook, but I'm not finding the right way!
If I post a message, it goes well, but if I load picture nothing happens! The callback function get never called..
var bitmapData:BitmapData=new BitmapData(mc.width, mc.height);
bitmapData.draw(mc);
var bitmap:Bitmap = new Bitmap(bitmapData);
var params:Object = { image:bitmap, message:'Test Photo', fileName:'FILE_NAME' };
Facebook.api("/me/photos", onComplete, params);
EDIT
It works calling the function above with a mouse or keyboard event! I don't understand why calling it directly still not works.
I think that the problem shold be that a user action is required when you try to publish.

jQuery Live -- fire when item added to page

I've got an Ajax update happening to my MVC view. It displays a message telling the user the operation has completed:
<% if (ViewData["colorOptionsMessage"] != null) { %>
<span class="ajaxMessage"><%= ViewData["colorOptionsMessage"] %></span>
<% } %>
I want to atuomatically fade this message out once it appears, and I'd like to do it once, and have it work site-wide. This is what I tried, which doesn't work (the message appears, but the alert does not show):
$(function () {
$(".ajaxMessage").live("load", function () {
alert("once I can get this to show I'll put in a jueryUI fadeOut"); });
});
EDIT
Just to be clear, I don't need help with the fade out code; I just need help getting this call to Live() to wire up properly.
There's no direct way to be informed automatically when new elements are added to the page. $('.ajaxMessage').live('load') would only happen when the load event fires on an image, iframe or object/embed/applet with class="ajaxMessage", a load event is not fired with its own target for every new element that enters the page.
You could only do this by (a) DOM Mutation Events, which generally aren't widely enough supported, or (b) constantly polling to fetch the .ajaxMessage selector and seeing if any new elements appear in the results.
Better to manually $('.ajaxMessage', function() {...}) immediately after (potentially) adding the content to the page, in the ajax() method's success handler.
ETA:
that jQuery handler doesn't seem to execute after an ajaxForm success
If you can't catch success directly you could try registering a global success handler using ajaxSuccess.
The code below expects you made the Ajax call through jQuery. if the ajax call was not through jQuery, then ignore this answer. Could we see the ajax call itself?
<Script type="text/javascript">
$(function () {
// this is a jQuery global ajax event that fires for every ajax, you need to check the URL
$.ajaxSuccess(function(e, xhr, settings){
if (settings.url == 'URI/ for/ajax /message/load.') {
alert("once I can get this to show I'll put in a jueryUI fadeOut");
}
});
);
</script>
When i want to add something, wait a few, and hide it, I use setTimeout function instead of live events. I add the code on the success callback.
This is a 1 second wait:
setTimeout(function(){ $("ajaxMessage").fadeOut(); }, 1000)
Of course, if you dont want to wait, just fadeOut the element in the success callback.
Can this be enough for you?
I dont think you can bind load to span.
only to IMG IFRAME BODY
As I know "ready" and "load" events are not supported by jQuery in "live". So you can use plugins as this one http://startbigthinksmall.wordpress.com/2011/04/20/announcing-jquery-live-ready-1-0-release/
Here is the demo http://cdn.bitbucket.org/larscorneliussen/jquery.liveready/downloads/demo.html

Using html5 video events on the iPhone, how do I tell "Done" button click from a simple pause?

I've got a web page for the iPhone that uses the HTML5 video tags. On the iPhone, such embedded videos are played in the native player. I wanted to check when the video had ended and when the user had dismissed the video with the "Done" button. Initially, I tried this:
var video = $("#someVideo").get(0);
video.addEventListener('ended', myFunction);
But that only fired when the video was allowed to finish. After some playing around with other events (suspend, stalled, waiting) I found that the "Done" button triggers a 'pause' event. However, when I add this:
video.addEventListener('pause', myFunction);
my code is called both from the "Done" button and when the user taps the pause button in the playback controls. The second case is undesirable; I only want the first case, but the events don't seem to be giving me enough information.
Does anyone know of a way to tell when the user has hit the "Done" button in the iPhone player (versus simply pausing)?
Just check the webkitDisplayingFullscreen boolean in your pause function. Pressing Done or Pause triggers the pause event, but Done does a wee bit extra like an exit from full screen mode. Doing that check will help you differenciate the 2 button presses.
Some sample code below.
<script>
var html5Video = function() {
return {
init: function() {
var video = document.getElementsByTagName('video')[0];
video.addEventListener('ended', endVideo, false);
video.addEventListener('pause', pauseVideo, false);
}
};
}();
function endVideo() {
alert("video ended");
}
function pauseVideo() {
var video = document.getElementsByTagName('video')[0];
if (!video.webkitDisplayingFullscreen)
endVideo();
}
html5Video.init();
</script>
This is what you need:
yourplayer.addEventListener('webkitendfullscreen', onPlayerExitFullscreen, false);
And vice versa
yourplayer.addEventListener('webkitbeginfullscreen', onPlayerEnterFullscreen, false);
Here's another answer to your question that I found: How to figure out when a HTML5 video player enters the full screen mode on iOS / iPads?
There is an event called "ended" that you should probably use, see http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#event-media-ended .

iPhone Web Application JavaScript events break after waking up from sleep

I'm trying to build a mobile-safari/iphone web-app using jQuery code I already wrote for the desktop version of the app. The problem I'm having is that when my phone goes to sleep with the web-app running, when I wake it up (slide to unluck) the JavaScript event handlers no longer function. In this case meaning when I click on a link that used to perform an AJAX update via an onclick event it actually follows the link by opening the page in a new Safari window, breaking the appearance of the native iPhone app.
The code that stops working:
$(function() {
var ajaxLoad;
var ajaxClick = function(e) {
e.preventDefault();
e.stopPropagation();
$("body").load( $(this).attr("href"), ajaxLoad );
}
ajaxLoad = function() {
$(this).find("a").click( ajaxClick );
}
$("a").bind( "click", ajaxClick );
});
When the code works the result of the link will open in the web-app frame, when it breaks, the code will open in a new safari window, breaking the look of an actual app.
Not tested - but would it help to add 'return false' to the end of the ajaxClick function so that the link does not activate.