Using multiple variables in FB Post?

0 favourites
  • 9 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Followed 's tutorial for a Facebook share button, and got it working fine to show a highscore variable on Facebook, I'm trying to display 2 variables in the Facebook post, highscore and the level they were on and just can't get it working. In my .php file I have

    <?php

    $score = $_GET["score"];

    $scorex = explode(":", $score);

    $highscore = $scorex[0];

    $level = $_GET["level"];

    $levelx = explode(":", $level);

    $levelsCompleted = $levelx[0];

    ?>

    <html>

    <head>

    <title>Site Name</title>

    <meta property="og:title" content="I got <?echo $highscore;?> on Level <?echo $levelsCompleted;?> in this game!"/>

    <meta property="og:image" content="http://mywebsite.com/game.png"/>

    <meta property="og:site_name" content="Game Title"/>

    <meta property="og:description" content="I got <?echo $highscore;?> on Level <?echo $levelsCompleted;?> in this game!"/>

    </head>

    <body>

    <meta http-equiv="refresh" content="0;URL=http://www.mysite.com" />

    </body>

    </html>

    Then I have this code on my on touch event/browser event

    "https://www.facebook.com/sharer/sharer.php?u=http://www.mysite.com/share.php? score="& highscore & ":" & random(1,0) & "level="& levelsCompleted & ":" & random(1,0)

    The highscore works fine but I can't get the levels to show up, not sure if it's the .php or my browser event is wrong. Any help would be appreciated, thanks.

  • Bump, really stuck on this, can't figure it out.

  • This may not work but it's probably worth a go. Try putting the url into a string variable first and then open the browser object with that variable in a subsequent event.

    I have no experience with php so can't help on the rest I'm afraid.

  • Aren't you missing a "&" in your URL string between both parameters?

    The final string should be

    facebook.com/sharer/sharer.php score=1000:0&level=3:1

    for example. You need to put the "&" before level, like so:

    "https://www.facebook.com/sharer/sharer.php?u=http://www.mysite.com/share.php?score=" & highscore & ":" & random(1,0) & "&level=" & levelsCompleted & ":" & random(1,0)

    Also, you should use a larger random range (like 1 to 10). The whole point of using the random function there is to make sure that facebook gets a new URL every time and doesn't use the cache

  • This may not work but it's probably worth a go. Try putting the url into a string variable first and then open the browser object with that variable in a subsequent event.

    I have no experience with php so can't help on the rest I'm afraid.

    Tried the string but couldn't get it working with the php.

  • Aren't you missing a "&" in your URL string between both parameters?

    The final string should be

    https://www.facebook.com/sharer/sharer. ... /share.php? score=1000:0&level=3:1

    for example. You need to put the "&" before level, like so:

    "https://www.facebook.com/sharer/sharer.php?u=http://www.mysite.com/share.php?score=" & highscore & ":" & random(1,0) & "&level=" & levelsCompleted & ":" & random(1,0)

    Also, you should use a larger random range (like 1 to 10). The whole point of using the random function there is to make sure that facebook gets a new URL every time and doesn't use the cache

    Just gave this a try and it didn't work, only the 1st variable shows up in the FB post, the 2nd variable is still blank. It's like I'm not targeting the 2nd variable right in the syntax in C2 for it to be able to get read by the GET in the php. I've tried the way you suggested "&level=" & levelsCompleted, tried it with just "level=" & levelsCompleted and nothing works, there has to be a way to get this to work.

    Also the (1,0) was actually a typo, I am using (1, 10).

  • Ok well nevermind this, I got everything working by making a FB app and using that instead of this sharer and was able to call as many variables as I want without the need for the php.

  • twg - Could you please share your method?

    I've been trawling the forums for a solution of how to post more interesting things using open-graph stories with an app [ website only ] - but as yet nothing is documented on the forum or manual on how to do more than publish a score.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)