Facebook APP first time running bug

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SmithGab
Forum Newbie
Posts: 1
Joined: Wed Jan 25, 2012 11:25 am

Facebook APP first time running bug

Post by SmithGab »

Hello!

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

Image

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>

Sorry my English :roll: And thank for all Reply 8)
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Facebook APP first time running bug

Post by twinedev »

I haven't done much with facebook apps yet, but it makes sense that you have to "install" it before acting upon it (letting you like it)

You say the user sees a white page. Have you checked the source to see if anything is actually there? Have you told it to dump out variables for you to see the values so you can trace the route the program is taking? Just going off of what is "seen" in the browser is only the first step.

-Greg
joeschoe
Forum Newbie
Posts: 1
Joined: Thu Jan 26, 2012 10:04 am

Re: Facebook APP first time running bug

Post by joeschoe »

I used the same sample routine from the facebook documentation.
I cant get the code to run as I get an error with the "try" instruction.

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;
}
}
I consistently get the following error:

PHP Parse error: parse error, unexpected '{' in c:\aaonyourfingertips\fblogintest.php on line 23

Is there some setting in the PHP5 running on a Linux server that needs attention?
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Facebook APP first time running bug

Post by twinedev »

Can you post the whole file up to this section as is, so we can see what line #23 is (and using the

Code: Select all

 button in the toolbar here to wrap it properly).

-Greg
Post Reply