I made a simple web game using Phaser.io and I now I would like to turn it into a facebook instant game. I've tried following some articles but it didn't work.
Do you know any good source (article, youtube tutorial...) about the process of making a facebook instant game from a web game?
To host a Phaser Web Game to Facebook Instant Games, follow these steps:
First, you need to create a new Facebook app.
You will now land on the app dashboard, now you will select “Settings”, then “Basic”.
Now in the category select “Games”, then choose the category which fits best to your game.
Back to the dashboard, let’s select “Instant Games”.
Now you have to fill in some information, be sure “Use Instant Games” is set to “Yes”.
Now you have to upload a zipped file with the game. You can do this operation under “Web Hosting” panel, selecting “Upload Version”,
then pushing it to production by clicking on the star icon.
After, you have to include the Facebook Instant Games API in your index file:
<script src="https://connect.facebook.net/en_US/fbinstant.6.0.js"></script>;
Then, in your game file, when you normally create the game itself on window.onload function, you will have to create it this way:
FBInstant.initializeAsync().then(function() {
FBInstant.setLoadingProgress(100);
FBInstant.startGameAsync().then(function() {
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
if(windowWidth > windowHeight){
windowWidth = windowHeight / 1.8;
}
var gameWidth = windowWidth * gameOptions.gameHeight / windowHeight;
game = new Phaser.Game(gameWidth, gameOptions.gameHeight, Phaser.CANVAS);
game.state.add("Boot", boot);
game.state.add("Preload", preload);
game.state.add("TitleScreen", titleScreen);
game.state.add("PlayGame", playGame);
game.state.start("Boot");
})
})
You can check this tutorial for more details & visual instructions.
Related
I can successfully publish a Facebook Achievement, but it only apears on my activity log.
There I have the option to change its visibility from "Allowed on timeline" to "Shown on timeline" or "Hidden from timeline".
When I change it to "Shown on timeline" it apears on my timeline, and that's the default behaviour I'd like to happen.
How can I change the default behaviour to "Shown on timeline"?
I'm using Unity (latest version: 5.4.2) and Facebook SDK for Unity (latest version: 5.1).
This is the relevant piece of code:
var query = new Dictionary<string, string>();
query["achievement"] = achievementUrl;
FB.API("/me/achievements", Facebook.HttpMethod.POST, callbackfunc, query);
Also, I wanted something similar for the Score, but in this case it is even worse.
When I publish a Score it just says in the activity log that I was playing game X - it doesn't even say I have a new highscore.
The code:
var query = new Dictionary<string, string>();
query["score"] = scoreString;
FB.API("/me/scores", Facebook.HttpMethod.POST, callbackfunc, query);
[Edit] - The score "story" is apearing in the activity log as well after all, so the problem is exactly the same as the achievements.
Facebook says:
This behavior is intended for the Achievement story and it's not meant to be shown on Timeline.
I recommend moving away from these implicit stories and integrate explicit stories where the user decides how and when to share back to Facebook.
Here's a guide on how to implement explicit sharing: https://developers.facebook.com/docs/opengraph/using-actions/v2.2#explicitsharing
I'm trying to implement achievements with the Facebook Unity SDK.
I was hoping somebody could give me a qualitative description of the process required to do this.
Here's what I've done so far.
Hosted the web build on a server
Created an achievements folder on this site and created a test achievements html file as in https://developers.facebook.com/blog/post/539/
My main confusion is the difference between registering an achievement and positing an achievement.
Is registering an achievement something that needs to be done only once and if so where should this be done? Do I need to create a script in unity that registers all the achievements for the game that I run before the rest of my testing?
Also I'm unsure how the method call works for registering and posting an achievement. I'm under the impression I need to
call FB.API(string endpoint,Facebook.HttpMethod,FacebookDelegate callback,Dictionary formData)
but I'm really not sure what the input arguments need to be.
Here's my attempt so far(I'm pretty sure the string endpoint I've used is wrong)
private void RegisterAchievement()
{
string achievement ="http://www.invadingspaces.com/unity/testing/Achievements/ach1.html";
string appID = "999408935255000";
string achievement_display_order = "1";
string achievement_registration_URL = "https://graph.facebook.com/"+ appID + "/achievements";
FB.API(achievement_registration_URL+","+"achievement="+ achievement+ "&display_order=" +achievement_display_order+ "&access_token=" + FB.AccessToken ,Facebook.HttpMethod.POST,null,null);
}
Thanks in advance.
I'd suggest looking at the general Facebook achievements API: https://developers.facebook.com/docs/games/achievements/
Also you can first test out what to actually put with the graph explorer then put that into graph.:
https://developers.facebook.com/tools/explorer
So for example to create a new achivement it's just this:
var dict = new Dictionary<string,string>();
dict["achievement"] = "<URL_TO ACHIEVEMENT_HERE>";
FB.API(FB.AppId+"/achievements", Facebook.HttpMethod.POST, null, dict);
To get all your game achievements, it's:
FB.API(FB.AppId+"/achievements", Facebook.HttpMethod.GET);
Then to award a player an achievement, it's just this:
var dict = new Dictionary<string,string>();
dict["achievement"] = "<URL_TO ACHIEVEMENT_HERE>";
FB.API(FB.UserId+"/achievements", Facebook.HttpMethod.POST, null, dict);
To get that player's achievment that they completed, it's:
FB.API(FB.UserId+"/achievements", Facebook.HttpMethod.GET);
I'm trying to create a website that pulls free songs from multiple sources and lets users play them by clicking on their cover art, and launching them in a docked music player on the bottom of the page. Soundcloud's api offers me a lot of songs, but they are in a streaming api format, not in mp3 form.
The music players that SoundCloud offers are great for these streaming songs, but it won't work with the mp3s I'm pulling from other sites. Mp3 players like Jplayer are great for the mp3s, but I can't figure out how to get it to work with the streaming soundcloud format.
Think of a site like ex.fm: http://ex.fm/search/bob%20dylan
They pull their audio tracks from many sources but it is all playable through their one player.
Any help with this would be great.
Thanks
Check SoundCloud API
http://developers.soundcloud.com/docs/api/reference#tracks
There is a stream_url property for every track that's streamable outside of SoundCloud.
You need to register your app on Soundcloud and get API Key. With that key you can stream the tracks in your own player.
Edit, thanks to gryzzly. Example of SoundCloud API used with jPlayer:
var SOUNDCLOUD_API = 'http://api.soundcloud.com',
CLIENT_ID = '?client_id=REPLACE_WITH_YOUR_CLIENT_ID';
$(document).ready(function() {
var apiRequest;
$.get(SOUNDCLOUD_API + '/tracks/6981096.json' + CLIENT_ID)
.done(handleRepsonse);
function handleResponse (soundData) {
$("#jquery_jplayer_1").jPlayer({
ready: function () {
$(this).jPlayer("setMedia", {
// stream_url is good enough for jPlayer,
mp3: soundData.stream_url + CLIENT_ID
});
},
swfPath: "http://www.jplayer.org/2.1.0/js"
});
}
});
And you can check it live at jsbin.com/ajaken/4/edit
For some time now I try to figure out how these guys were able to add "Sign online here" button which is "install App" button on their fan-page tab:
http://www.facebook.com/GuinnessIreland?v=app_165491161181
I've read around the web and couldn't come up with any solid solution. The FBML and FBJS documentation left me with nothing.
So please, if anyone can help me with this.
NOTE: To make multiple tests on the Ajax request that are sent, do not accept the App install. It behaves differently after that.
I had some problems with finding out about it as well. There is no info about this kind of behavior in wiki or anywhere. I got it working after trying some possible solutions and the simplest one is to make user interact with content embedded in fan page tab such as click on something etc. Then you need to post an ajax request with requirelogin parameter to pop up to come out. The simple example would be:
user_ajax = function() {
var ajax = new Ajax();
ajax.responseType = Ajax.RAW;
ajax.requireLogin = true;
ajax.ondone = function(data) {
new Dialog(Dialog.DIALOG_POP).showMessage('Status', data, button_confirm = 'Okay');
}
var url = "http://yourappurl.com/request_handler"
ajax.post(url);
}
And the trigger for it:
Interaction
Then if user is known to be using your application (fan page tab) you can prompt him for additional permission like publish stream or email communication by calling:
Facebook.showPermissionDialog('publish_stream,email');
Hope this solves the problem.
Is there an easy way to design a website to facilitate an iphone user providing gps coordinates to the site?
I am wondering if there might be a naming convention for form fields for example, to let the user input in an automated way.
I am considering building a location based website and would like to tailor it for iphone (and other mobile users). I realize an iphone app could do this but I'm not equipped to create one.
Here's a snippet on how to read location from the iPhone. Looks like it requires 3.0:
navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
function foundLocation(position)
{
var lat = position.coords.latitude;
var long = position.coords.longitude;
alert('Found location: ' + lat + ', ' + long);
}
function noLocation()
{
alert('Could not find location');
}
See: http://mapscripting.com/how-to-use-geolocation-in-mobile-safari
By the way, if you want to use web code on the iPhone, there are a couple middle-ground solutions you could try that don't force you to create a native app but allow you to wrap your site in an app and get access to GPS and other native features.
PhoneGap: http://phonegap.com/
Appcelerator: http://www.appcelerator.com/products/titanium-mobile/
Check out the app SendLocation under navigation by Jouni Erola.
Its a simply app that will send out the lat & lon of the iPhone to YOUR server.
Simply enter your server url to receive the location as HTTP-GET methid
I've don this without any programming. You can:
Download the iPhone app "Basic GPS" from iPhone Store.
Start an account at Twitter.com (if you don't already got one).
Start an e-mail-to-twitter account at Twittermail.com.
In Basic GPS settings use your secret e-mail address from Twittermail.
At Twitter.com/widgets click "Other" to get your HTML-code for publishing your Tweets elsewhere.
Put this HTML code on your homepage.
In Basic GPS you just click the blue "I" (on) button, "Email" and "Send" to send your position to Twittermail, which publish it on Twitter. And Twitter will automaticly publish it on your homepage.
See a working axample at http://CharlieBloom.com. Only the 3 latest (customizeable) Tweets are visible, click on "Follow me on Twitter" to se "My position ....." and a Google Maps-link. Positions are updated on my website 2-3 minutes after I have sent them.
Best regards,
Charlie Bloom
Yes, but the accuracy is pretty bad. I just built a web form that posts GPS settings from the watchPosition() function to my database and then maped the results. While paddling down a local river it got only two of seven posts correct. The rest were outside the river, and two of those were about a mile away! I'm now looking for a better solution.
Here's the code I use to update the form fields:
<script type="text/javascript">
function getGPSLocation()
{
if(navigator.geolocation)
{
navigator.geolocation.watchPosition(onGeoSuccess);
} else {
alert("Your browser or device doesn't support Geolocation");
}
}
function onGeoSuccess(position) {
document.getElementById("Latitude").value = position.coords.latitude;
document.getElementById("Longitude").value = position.coords.longitude;
}
</script>
And this is the form. Update to suite your needs.
<form>
<img src="spacer.gif" OnLoad="getGPSLocation();">
<input type="Text" name="Latitude" id="Latitude" value="">
<input type="Text" name="Longitude" id="Longitude" value="">
</form>