4

Is there any way to schedule a task in a Facebook app, that I am going to create? I would like it to run some operation every week.

EDIT For example I would like to schedule posting something on someone's wall at certain time of a week. Is it possible?

EDIT2 And can I also send a private message to the user from my app instead of posting on a wall?

gruszczy
  • 40,948
  • 31
  • 128
  • 181

1 Answers1

3

Could you explain a little bit more ?

Facebook applications have NOT the ability to run scheduled tasks BUT facebook applications are mainly websites connected to facebook or iframes integrated into facebook.

So you'll have to run your scheduled tasks on your server directly using something like CRON jobs.

A quick example :

Let say your facebook application is located at : http://yourserver.com/facebookapp1/ You could schedule a task on your server that will call the page http://yourserver.com/facebookapp1/scheduledtaks/

So basically it will call this page every week or day and this page will do the job of doing whatever you need to for your maintenance ...

Do you have a web server ? Can you add cron jobs ? What is your server technology ? If you give us more information we could give you a more specific answer ...

To answer your edit :

It is possible, you need to create a script that you will call everyday for example. Let's call it check_and_send. Now your script would need to check if something is to be send (It depends on your logic) like check a DB to see if something need to be posted today or not. When it want to publish something it can do it using the facebook graph api. You will need to ask for the 'publish_stream' permission to the user.

Also you will need a preliminary step where you ask the user to authenticate to facebook and you ask him to grant your application the 'publish_stream' permission but ALSO the 'offline_access' permission, so you can publish to the user wall at any time (and not only when he is connected) ... see facebook permissions

After that you will have to save the access_token (for each user) in your DB or somewhere and you will use it when you need to post on the wall of that particular user ...

So in short :

1) (once) authenticate the user,ask for permissions, save it's facebook UID and access_token

2) (periodically) check in your DB if something need to be posted, if yes post it using the facebook graph api and the saved access_token.

dwarfy
  • 3,076
  • 18
  • 22
  • Hi gruszczy, Please see my answer in my edited post ... and let me know if you need more info.. – dwarfy Apr 24 '11 at 11:23
  • This is a great answer. I added a second edit. Would you be so kind and answer it too? – gruszczy Apr 24 '11 at 11:24
  • About your **edit2** this NOT possible at the moment, see [here](http://stackoverflow.com/questions/2574431/facebook-api-send-messages-to-friends). – dwarfy Apr 24 '11 at 11:36
  • We don't have `offline_access` permission anymore, then how can I send a post/message after the token has expired? There is a way to do that? – Gustavo Straube Oct 12 '12 at 15:42