Question

in my application it posts photo created, to user's "photos". But presenlty whenever user uses application it creates photo and can be posted on photo album.

is it ok? or i should delete old photo and upload as new ? or restrict user from using application again ? or anything else i shud follow ?

Was it helpful?

Solution

Is it ok? No, I don't like doing it and you will be flagged as spam quickly.

Should you delete old photo and upload as new? No, this requires more permissions and there are alternatives.

Should you restrict user from using application again? No.

Anything else i should follow? Yes.

I had one of my apps set up in a similar way but this is what I ended up doing instead...

I store each user in my database table 'users' with one column for the Facebook id ( 'fbid' ) and one for the time of that users last post ( 'lastpost' ). In my database the default value for 'lastpost' is 0

This part I use in all of my Facebook applications to track/insert new users:

$seeif = mysql_num_rows(mysql_query("SELECT id FROM users WHERE fbid='$user' LIMIT 1"));

if ( $seeif == "1" ) {
// already exists
} else {
// insert new user
mysql_query("INSERT INTO users (fbid) VALUES('$user' ) ") 
or die(mysql_error()); 
}

This part will query that table to see what time their 'lastpost' was (if they haven't posted yet it will return the table default of 0 :

$adesult = mysql_query("SELECT lastpost FROM users WHERE fbid='$user' LIMIT 1") 
or die(mysql_error());  
while($ardw = mysql_fetch_array( $adesult )) {
$alast = $ardw['lastpost'];

This is where I decide if I want to post and if so, update the database with a new value for 'lastpost' of the current user.

Note: I current have it set to post no more frequently than every 5min (300 seconds) change the first line to meet your specifications.

$mathtime = time() - 300;

if ( $alast > $mathtime ) {
// do nothing, user has posted in the past 5min
} else {
// post
$dothepost=1;
$currenttime = time();
mysql_query("UPDATE users SET lastpost='$currenttime' WHERE fbid='$user' LIMIT 1") 
or die(mysql_error());
}

And finally here is the code for the image post:

if ( $dothepost == "1" ) {

if ($user) {
      try {
$path_to_image = "/home/path/to/your/image/goes/here.jpg";
$args = array(
  'message' => 'Hello world!',
  'image'   => '@' . realpath($path_to_image),
);

$data = $facebook->api('/me/photos', 'post', $args);

      } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
      }
}

} else {
// noth
}

From your question it is not really clear if your page displays/posts the same image each time or if it is dynamic and displays/posts different images. If you will be displaying the same image each time:

Change:

if ( $dothepost == "1" ) {

To:

if ( $alast == "0" ) {

Otherwise, you will end up with an album full of the same image posted every time they access that page (so long as each visit is 5 min. apart)

Hope this helps someone

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top