Using multiple variables in FB Post?

Get help using Construct 2

Post » Sat Jul 05, 2014 7:49 am

Followed @stctr '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.
B
47
S
16
G
2
Posts: 109
Reputation: 4,307

Post » Mon Jul 07, 2014 3:17 am

Bump, really stuck on this, can't figure it out.
B
47
S
16
G
2
Posts: 109
Reputation: 4,307

Post » Mon Jul 07, 2014 3:39 am

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.
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,207
Reputation: 43,836

Post » Mon Jul 07, 2014 6:21 am

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

The final string should be
https://www.facebook.com/sharer/sharer.php?u=http://www.mysite.com/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
B
6
S
2
Posts: 79
Reputation: 608

Post » Mon Jul 07, 2014 9:55 am

Colludium wrote: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. :(
B
47
S
16
G
2
Posts: 109
Reputation: 4,307

Post » Mon Jul 07, 2014 9:56 am

monitz87 wrote: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).
B
47
S
16
G
2
Posts: 109
Reputation: 4,307

Post » Mon Jul 07, 2014 11:24 am

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.
B
47
S
16
G
2
Posts: 109
Reputation: 4,307

Post » Sun Jul 27, 2014 12:48 am

@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.
Image
B
27
S
9
G
5
Posts: 488
Reputation: 11,948

Post » Sun Jul 27, 2014 5:13 am

@JohnnySix I just used this method https://www.scirra.com/tutorials/914/fa ... r-cocoonjs and used this for encoding http://meyerweb.com/eric/tools/dencoder/ .
B
47
S
16
G
2
Posts: 109
Reputation: 4,307


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 13 guests