Create a Facebook application like “Friend interview” – Step 3

Here we go with the 3rd step. In this tutorial you will learn how to publish a full featured feed post to your friends’ wall, and to handle “umlauts” characters like “äöü” for the pleasure of our German readers, and for every user who has friends whose names contain special characters.

This is the kind of feed you are going to publish:

And this is the link of the application, just in case you want to have a look: About you Facebook application

The code is almost similar to the one we used in step 2:

'157934074246374','secret'=>'dontstealmysecretkey','cookie'=>true,'domain'=>'gamesalsa.com'));

$session = $facebook->getSession();
 
if(!$session){
	$url = $facebook->getLoginUrl(array('canvas'=>1,'fbconnect'=>0,'req_perms'=>'publish_stream','next'=>'http://apps.facebook.com/about_you_game/','cancel_url'=>'http://apps.facebook.com/about_you_game/'));
	echo "

Redirecting to permission request...

"; echo ""; } else{ if($_POST[to_do]=="Answer and publish"){ $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/$_POST[user]/feed"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1) ; curl_setopt($ch, CURLOPT_POSTFIELDS, "access_token=$session[access_token]&message=".urlencode("just answered a question about you:")."&link=".urlencode("http://apps.facebook.com/about_you_game/")."&picture=".urlencode("http://www.gamesalsa.com/aboutyou/about_you_icon.png")."&name=".urlencode("Do you think $_POST[name] likes this app ?")."&caption=".urlencode("and the answer is...")."&description=".strtoupper(urlencode($_POST[answer]))."&actions=".urlencode("{\"name\": \"Play now\", \"link\": \"http://apps.facebook.com/about_you_game/\"}")); $result = curl_exec($ch); curl_close($ch); } $friends = $facebook->api('me/friends'); $number_of_friends = count($friends[data]); $random = rand(0,$number_of_friends-1); $friend_id = $friends[data][$random][id]; $friend_name = $friends[data][$random][name]; $img = "http://graph.facebook.com/$friend_id/picture?type=large"; } ?>
Do you think likes this app?

Using proper html tags such as http-equiv at line 38 allow us to properly render special characters, while the key of this post is line 20, where we pass a lot more information than in step 2.

Let’s see it in detail:

access_token: it’s the access token required to publish on friends’ wall. Its value must be

$session[access_token]

message: it’s the message which will appear next to your name. I used

urlencode("just answered a question about you:")

because I wanted my friend to see “Emanuele Feronato just answered a question about you:”. I also used urlencode although it’s useless in this case, just not to forget to encode the string should I change it in the near future with another string with some special characters.

picture: the absolute URL of the picture to display on the left of your post.

urlencode("http://www.gamesalsa.com/aboutyou/about_you_icon.png")

name: it’s the name of the link you are publishing in the feed. This is where we will place the question.

urlencode("Do you think $_POST[name] likes this app ?")

link: it’s the link attached to the picture and the name. You may want to use the URL of the application itself.

urlencode("http://apps.facebook.com/about_you_game/")

caption: the caption of the link, placed just under the link itself. Don’t write anything important here as it won’t be noticed that much since the blue color of the link grabs almost all attention. Perfect to write something like “and the answer is…”

urlencode("and the answer is...")

description: it’s the description of the link and it’s the longest text you can enter. We’ll place the answer there.

strtoupper(urlencode($_POST[answer]))

actions: you can also add a custom action to the action footer of the post (where you can find “Like”, “Comment”, and so on). Actions should be added as a JSON list containing “name” and “link”

urlencode("{\"name\": \"Play now\", \"link\": \"http://apps.facebook.com/about_you_game/\"}")

And here you, go, have a try with the application: About you Facebook application.

Get the most popular Phaser 3 book

Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

Get the book

214 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 100 rounds
// 10000000
// 2 Cars
// 2048
// A Blocky Christmas
// A Jumping Block
// A Life of Logic
// Angry Birds
// Angry Birds Space
// Artillery
// Astro-PANIC!
// Avoider
// Back to Square One
// Ball Game
// Ball vs Ball
// Ball: Revamped
// Balloon Invasion
// BallPusher
// Ballz
// Bar Balance
// Bejeweled
// Biggification
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Boom Dots
// Bouncing Ball
// Bouncing Ball 2
// Bouncy Light
// BoxHead
// Breakout
// Bricks
// Bubble Chaos
// Bubbles 2
// Card Game
// Castle Ramble
// Chronotron
// Circle Chain
// Circle Path
// Circle Race
// Circular endless runner
// Cirplosion
// CLOCKS - The Game
// Color Hit
// Color Jump
// ColorFill
// Columns
// Concentration
// Crossy Road
// Crush the Castle
// Cube Jump
// CubesOut
// Dash N Blast
// Dashy Panda
// Deflection
// Diamond Digger Saga
// Don't touch the spikes
// Dots
// Down The Mountain
// Drag and Match
// Draw Game
// Drop Wizard
// DROP'd
// Dudeski
// Dungeon Raid
// Educational Game
// Elasticity
// Endless Runner
// Erase Box
// Eskiv
// Farm Heroes Saga
// Filler
// Flappy Bird
// Fling
// Flipping Legend
// Floaty Light
// Fuse Ballz
// GearTaker
// Gem Sweeper
// Globe
// Goat Rider
// Gold Miner
// Grindstone
// GuessNext
// Helicopter
// Hero Emblems
// Hero Slide
// Hexagonal Tiles
// HookPod
// Hop Hop Hop Underwater
// Horizontal Endless Runner
// Hundreds
// Hungry Hero
// Hurry it's Christmas
// InkTd
// Iromeku
// Jet Set Willy
// Jigsaw Game
// Knife Hit
// Knightfall
// Legends of Runeterra
// Lep's World
// Line Rider
// Lumines
// Magick
// MagOrMin
// Mass Attack
// Math Game
// Maze
// Meeblings
// Memdot
// Metro Siberia Underground
// Mike Dangers
// Mikey Hooks
// Nano War
// Nodes
// o:anquan
// One Button Game
// One Tap RPG
// Ononmin
// Pacco
// Perfect Square!
// Perfectionism
// Phyballs
// Pixel Purge
// PixelField
// Planet Revenge
// Plants Vs Zombies
// Platform
// Platform game
// Plus+Plus
// Pocket Snap
// Poker
// Pool
// Pop the Lock
// Pop to Save
// Poux
// Pudi
// Pumpkin Story
// Puppet Bird
// Pyramids of Ra
// qomp
// Quick Switch
// Racing
// Radical
// Rebuild Chile
// Renju
// Rise Above
// Risky Road
// Roguelike
// Roly Poly
// Run Around
// Rush Hour
// SameGame
// SamePhysics
// Save the Totem
// Security
// Serious Scramblers
// Shrink it
// Sling
// Slingy
// Snowflakes
// Sokoban
// Space Checkers
// Space is Key
// Spellfall
// Spinny Gun
// Splitter
// Spring Ninja
// Sproing
// Stabilize!
// Stack
// Stick Hero
// String Avoider
// Stringy
// Sudoku
// Super Mario Bros
// Surfingers
// Survival Horror
// Talesworth Adventure
// Tetris
// The Impossible Line
// The Moops - Combos of Joy
// The Next Arrow
// Threes
// Tic Tac Toe
// Timberman
// Tiny Wings
// Tipsy Tower
// Toony
// Totem Destroyer
// Tower Defense
// Trick Shot
// Tunnelball
// Turn
// Turnellio
// TwinSpin
// vvvvvv
// Warp Shift
// Way of an Idea
// Whack a Creep
// Wheel of Fortune
// Where's my Water
// Wish Upon a Star
// Word Game
// Wordle
// Worms
// Yanga
// Yeah Bunny
// Zhed
// zNumbers