Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - rgpaddler

Pages: 1
1
News / Re: Stencyl 4.0.3 - Release Candidate
« on: August 04, 2020, 09:34:24 pm »
Great that you are still working on this - making stencyl games has literally kept me reasonably sane through-out the last  crazy 6  months,I might even reach the stage of publishing very soon,at which point I'll be subscribing.Respect and thank you!  :) :) :)

2
Old Questions (from 1.x/2.x) / Re: Facebook integration
« on: March 13, 2013, 08:41:42 am »
Hi - I managed to get posts,shares and likes working from a flash (cs 5.5) app on facebook.The swf needs to be hosted on an secure site so I used the free heroku hosting that is offered when you click on the 'create new app'.Then,after much searching across the web I finally pieced together this index.php to embed the swf.I literally just copied this from the server,so it definately works as of 13/03/13..

Code: [Select]

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>

<meta property="og:title" content="YOUR APP DESCRIPTION" />
<meta property="og:type" content="activity" />
<meta property="og:url" content="https://apps.facebook.com/YOUR_FB_APP_URL/" />
<meta property="og:image" content="https://YOUR_HEROKU_URL.herokuapp.com/279x205.gif" />
<meta property="og:site_name" content="YOUR_FB_APP_TITLE" />
<meta property="fb:app_id" content="YOUR_FB_APP_ID" />

<center>
    <!-- Include support librarys first -->
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
    <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
 
    <script type="text/javascript">

        var APP_ID = "YOUR_FB_APP_ID";
        var REDIRECT_URI = "https://apps.facebook.com/YOUR_FB_APP_URL/"
        var PERMS = "publish_stream"; //comma separated list of extended permissions


function inviteFriends(arg) {
     FB.ui({
          method : 'apprequests',
          title : arg.title,
          message : arg.message
     },
     function(response) {
          var fla = document.getElementById('Main');
          if (response && response.to) {
               console.log('User invited at least 1 friend.');
               console.log(response);
          } else {
               console.log('User canceled invitation.');
               console.log(response);
          }
     fla.invitationCallback(response);
     });
 }


        function facebookPost(arg){
FB.ui(
  {
                     method       : 'feed',
                                name              : arg.name,
                                link              : arg.link,
                                picture   : arg.picture,
                                caption   : arg.caption,
                                description  : arg.description
  },

                function(response) {
                                        var fla = document.getElementById('ConnectDemo');
                                        if (response && response.post_id) {
                                                //alert('Post was published.');
                                        } else {
                                                //alert('Post was not published.');
                                        }
                                        console.log(response);
                                        fla.postCallback(response);
                                }

);
}
       
       
         
        function init()
        {
            FB.init({appId:APP_ID, status: true, cookie: true});
            FB.getLoginStatus(handleLoginStatus);
        }


 
        function handleLoginStatus(response)
        {
            if (response.authResponse && response.status==="connected")
            {
                //Show the SWF
                $('#ConnectDemo').append('<h1>You need at least Flash Player 9.0 to view this page.</h1>');
                swfobject.embedSWF("YOUR_APP.swf",
                    "ConnectDemo", "700", "518", "11.0", null, null, null, {name:"ConnectDemo"});
 
            }
            else
            {
                var params = window.location.toString().slice(window.location.toString().indexOf('?'));
                top.location = 'https://graph.facebook.com/oauth/authorize?client_id='
                    +APP_ID
                    +'&scope='+PERMS
                    +'&redirect_uri=' + REDIRECT_URI
                    + params;
            }
        }
        $(init);
    </script>
<script type="text/javascript">
    var flash = document.getElementById( "ConnectDemo" );
    flash.confirmPost( < ?= $post_id; ?> );
</script>
</head>
<body>
        <div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="https://apps.facebook.com/YOUR_FB_APP_URL/" data-send="false" data-width="450" data-show-faces="true"></div>
    <div id="ConnectDemo"></div>
</body>
</center>
</html>



Then within actionscript,you make calls to external interface.These are the essential bits (and I mean - BITS!) of the actionscript that connect flash to facebook.For it to work it needs the graphApiScource which you can get off google code at http://code.google.com/p/facebook-actionscript-api/downloads/detail?name=GraphAPI%20Source_1_5.zip and point to the api from within actionscript settings

Code: [Select]

import com.facebook.graph.Facebook;
import com.facebook.graph.data.FacebookSession;
import com.facebook.graph.net.FacebookRequest;
Security.loadPolicyFile("http://graph.facebook.com/crossdomain.xml");
Security.loadPolicyFile("http://profile.ak.fbcdn.net/crossdomain.xml");
const APP_ID:String = "YOUR_APP_ID";
Facebook.init(APP_ID, handleLogin, {channelUrl : 'https://YOUR_HEROKU_URL.herokuapp.com/channel.html'});
loginButton.addEventListener(MouseEvent.CLICK, onLoginButtonClicked);
function onLoginButtonClicked(event:MouseEvent):void
{
if (Facebook.getSession() && Facebook.getSession().accessToken == null)
{
Facebook.login(handleLogin, {scope:"publish_stream"});
}
else
{
Facebook.logout(handleLogout);
}
}

function handleLogin(response:Object, fail:Object):void
{
if (Facebook.getSession().accessToken)
{
changeToLoginState();
}
}

function changeToLoginState():void
{
loginButton.visible = false;
loadMyInfo();

}

function loadMyInfo():void
{
Facebook.api('/me', onMyInfoLoaded);
}

function handleLogout(success:Object):void
{
loginButton.visible = true;
nameTextField.text = "user you are not logged in.";
}
function onMyInfoLoaded(response:Object,fail:Object):void
{
nameTextField.text = response.name;
playername = response.first_name;
}


Then to post a detailed message to the users wall,you use:-

Code: [Select]
var fbpost:Object = {name:"APP NAME",link:"https://apps.facebook.com/APP_URL/",picture:"https://YOUR_HEROKU_APP.herokuapp.com/img/yourImage.jpg",caption:playername + " found " + obj + " hidden behind door ",description:"your message"};


if (ExternalInterface.available)
{
ExternalInterface.call('facebookPost', fbpost);
ExternalInterface.addCallback('postCallback', postCallback);
}
function postCallback(arg:String):void
{
textbox.text = arg;
}

Then on the invite button you have:-

Code: [Select]
function invitebutton(event:MouseEvent):void
{

var fbinvite:Object = {title:"HELLO",message:"I LIKE WOMBATS"};


if (ExternalInterface.available)
{
ExternalInterface.call('inviteFriends', fbinvite);
}
}

That all works OK - but I have no idea if there is anyway of integrating this with stencyl.I'm generally pretty poor at coding,which is why I'm experimenting with stencyl rather than actionscript or flex.I've noticed theres quite alot of room for inserting your own attributes etc though so it may well be perfectly possible.

As some one mentioned earlier - facebook do change their policies all the time,but the code above seems fairly robust and has survived the last 2 years at any rate!! Connecting to the graph appears to be the key.Sorry I can't be of any more help.RG  :-\

Pages: 1