I create a simple funny facebook app, and place to my facebook page tab.
I have wanted that the user visit the tab, the application displayed "Please klick Like button before using this Application" After this, he needs to Install my application, and after installation the app make upload funny image.
Unfortunatelly, the first time visiting page tab, the scenario is fault.
The first event: the app request installation, and if it's accept, facebook redirect to my website and stop activity, and nothing happend, user see white website.
If user go back facebook manualy, and visit again my page tab , tha application work fine. (becuase my app have been istalled already ) App write "please like....." and after like button push the app upload image.
What's the problem? Where is the bug?
I want this scenerio:
1:user visit page tab, the app write: please like this site, if you want use this application
2:app request installation
3:app upload photo
this is my app's setting
And this is app PHP code.
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<? require 'src/facebook.php';
$app_id = "296503173730464";
$app_secret = "84153dbef01d19a4077cbcf38dc009a9";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$facebook->setFileUploadSupport(true);
// Get the url to redirect for login to facebook
// and request permission to write on the user's wall.
$login_url = $facebook->getLoginUrl(
array('scope' => 'publish_stream')
);
// If not authenticated, redirect to the facebook login dialog.
// The $login_url will take care of redirecting back to us
// after successful login.
if (! $facebook->getUser()) {
echo <<< EOT
<script type="text/javascript">
top.location.href = "$login_url";
</script>;
EOT;
exit;
}
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
$signed_request = $facebook->getSignedRequest();
function parsePageSignedRequest() {
if (isset($_REQUEST['signed_request'])) {
$encoded_sig = null;
$payload = null;
list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
$data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
return $data;
}
return false;
}
if($signed_request = parsePageSignedRequest()) {
if($signed_request->page->liked) {
//Create an album
$album_details = array(
'message'=> 'Woodoo Átok',
'name'=> 'Woodoo Átok'
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);
//Get album ID of the album you've just created
$album_uid = $create_album['id'];
//Upload a photo to album of ID...
$photo_details = array(
'message'=> "".$user_profile[name]." megtudta, hogy milyen Woodoo átok fogja érni! Kíváncsi vagy, hogy Téged elér-e egy Woodoo átok? Megtudhatod csak klikkelj ide: https://www.facebook.com/pages/SmithTestSite/331515576871462?sk=app_296503173730464"
);
$file[0]='wd_01.jpg';
$file[1]='wd_02.jpg';
$file[2]='wd_03.jpg';
$file[3]='wd_04.jpg';
$file[4]='wd_05.jpg';
$file[5]='wd_06.jpg';
$file[6]='wd_07.jpg';
$file[7]='wd_08.jpg';
$file[8]='wd_09.jpg';
$file[9]='wd_10.jpg';
$file[10]='wd_11.jpg';
$file[11]='wd_12.jpg';
srand(time());
$random = (rand()%11);
$photo_details['image'] = '@' . realpath($file[$random]);
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
echo "<IMG SRC='$file[$random]'><BR><BR>
<a href='$user_profile[link]' target='_parent'><< Klikkelj ide és máris látod az adatlapodon!</A>";
} else {
echo "<IMG SRC='wd-main-screen.jpg'>";// this image contain the text please click like if you are want use this application
}
}
?>
</body>
</html>