Using facebook off-line access to post on user's wall

Important notice! There was change in API in May 1, 2012. "offline_access" permission was deprecated. Quote: "For existing apps, there are no changes required for your app, but you should consider using the new endpoint". I have to re-write or add fallow up articles to my posts about "offline_access" permission about that suggestion/change. I also have to modify my example and live apps. But AFAIK - there is no hurry, because nothing gets broken that day. Read more about it here

Notice: This article is updated (july 2011) after initial publish because of changes in facebook API.

This is simplified and robust example how you can post on user's wall when she/he is not currently logged in or not using your application. It's achieved by by using stored access_token. Access tokens are needed to make calls on facebook graph api. Before that user has to allow offline_access permissions to your app. But let's take it step by step.

Also you may check out my previous post where I shared simple example of facebook iframe app with new php-sdk API. That would be good starting point if you are not familiar with facebook app development yet. And here is example app which uses this offline access permission.

This article uses $facebook object in examples. So before trying any of this out, create new facebook instance at the beginning of the script. It should look something like this.

//add php-sdk
require './facebook.php';

//Create facebook instance.
$facebook = new Facebook(array(
  'appId'  => 'application ID',
  'secret' => 'application secret',
  'cookie' => true,
));

Authorising url

First we need user to accept off-line access. When creating authorise url for your app, add 'offline_access' permission along others. This will grant permission to make such calls. This specific url is just a example but important part is here is req_perms parameter.

$loginUrl = $facebook->getLoginUrl(array(
	'canvas' => 1,
	'fbconnect' => 0,
	'req_perms' => 'publish_stream,offline_access',
	'next' => 'APP CANVAS URL IN FACEBOOK',
	'cancel_url' => 'URL WHERE TO REDIRECT WHEN ACCESS NOT GRANTED',
));
If using newer verions of facebook PHP SDK (v.3.0.0) (and up) use next one instead. Notice, that req_perms changed to scope
$loginUrl = $facebook->getLoginUrl(array(
	'canvas' => 1,
	'fbconnect' => 0,
	'scope' => 'offline_access,publish_stream'
));

Getting the token

If session is established, you can obtain it from session variables. That is all. Now you can store it in database or wherever you like and use it in your script when needed.

//get session
$session = $facebook->getSession();

//print out token stored in session
//using this you can do api calls even if
//user is not currently interacting with your app
if ($session) {
	echo $session['access_token'];
}
And if using newer verions of facebook PHP SDK (v.3.0.0) (and up) use next one instead
$user = $facebook->getUser();
if($user){
	echo $facebook->getAccessToken();
}

Using token for posting

Now the actual offline posting part. This is very simple. You only need that token gained earlier. This example shows how to post message on user's wall and get user's data. Also $res variable (array) will hold post ID if successfully posted. Code would be following.

//create message with token gained before
$post =  array(
	'access_token' => 'TOKEN HERE',
	'message' => 'This message is posted with access token - ' . date('Y-m-d H:i:s')
);

//and make the request
$res = $facebook->api('/me/feed', 'POST', $post);

//For example this can also be used to gain user data
//and this time only token is needed
$token =  array(
	'access_token' => 'TOKEN HERE'
);
$userdata = $facebook->api('/me', 'GET', $token);
Done! Nothing to add.

No gravatar aivable
Gayathri #
Excellently described. Thank you very much for post
No gravatar aivable
Bilal Ahmed #
Hi, Thanks you for such detailed tutorial, But I'm new to facebook development and i'm little confused on last part.

How do we actually post message on user wall? the line "$res = $facebook->api('/me/feed', 'POST', $post);"
will only store some data returned by api. Can you please explain little more with some more code sample.
No gravatar aivable
Bilal Ahmed #
OMG it was so simple.. :) Million Thanks buddy...I was searching it for days......... Amazing Tutorial...
No gravatar aivable
Balkini #
extraordinary tutorial ... it is so helpful
No gravatar aivable
Edd #
Hello, how can I contact developer here, who wrote this post?!? We need something like that developed and are looking for someone, who can do this )app for posting on useres wall, who has confirmed, taht we can do so). Please contact me by answering to this post. Thanks
Steinar #
This kinda works but user only stays logged in for maybe 10 minutes, and then I get ...

"Fatal error: Uncaught OAuthException: Error validating access token. thrown in facebook.php on line 543"

Any ideas? Do I need to store the "&expires_in=0" from the access_token somewhere?
No gravatar aivable
Steinar Knutsen #
I got this working beautifully! Thanks so much for sharing!
No gravatar aivable
sivakumar #
Hi , I want post the message to my fan page wall. Can u Please send me the code to post the message in the fan page wall, I am in great need of it. Thanks in Advance...
Janar Jürisson #
to sivakumar:

I think you can do it using "/YOUR_PAGE_NAME_OR_ID/feed" instead of "/me/feed" when posting used in my example.

Replace YOUR_PAGE_NAME_OR_ID with your page ID or alias.

So posting query becomes something like this:

$res = $facebook->api('/YOUR_PAGE_NAME_OR_ID/feed', 'POST', $post);

No gravatar aivable
sivakumar #
Hi Janar..

I tried both the things ..But it's not working.. I have send u the code Pls check it.
Janar Jürisson #
Ok, I dug a little bit into it. Seems that it's not so easy. It takes some extra rights and steps to do that.

Check out article http://developers.facebook.com/docs/authentication/ There is a subheading "Page Login". I would start there.
No gravatar aivable
sivakumar #
Hi, i tried the above code ..It's works superbly..The Tutorial was so nice ..Keep it Up...

Now i want to post the image in the wall. Can u Please send me the code ...Thanks in Advance.
Janar Jürisson #
Check out http://developers.facebook.com/docs/reference/api/post/ subheading "Publishing". There is a answer which properties you can send or get.

Something like this would work ...

$post = array(
'access_token' => 'TOKEN HERE',
'picture' => 'picture url here',
'link' => 'url',
'name' => 'title',
'caption' => 'caption',
'message' => 'message',
'description' => 'description'
);

$res = $facebook->api('/me/feed', 'POST', $post);
No gravatar aivable
avlon #
Thanks for this explanation which was very helpful!

I have a question, everything works fine but the content that i add to facebook via php (wall post, new albums, images, etc.) are all only visible by me. Does someone know why ?

No gravatar aivable
Gaurav Agarwal #
Can anyone help me, explain how do i fetch all the status of a person. I have the access token and offline permission is activated. I just need to know the api call.
No gravatar aivable
Majo #
Thanks a lot... It helped me...
{ Web-Farmer} #
Hi author,

This post helps me a lot ..

Information is very clean and neat.

Thanks
{ Web-Farmer }
No gravatar aivable
pushE #
Plz someone help I am getting the following error

Fatal error: Uncaught OAuthException: (#15) The method you are calling must be called with an app secret signed session thrown in______
No gravatar aivable
tzook #
a little question, this code works only when the user enters the script.

As in the code : "/me/feed/"...

that meant that the user entered the script gets msg 2 feed.

I want to make an script that will run weekly, and than post on the user's feed, without the need of him to enter the app.

how to run the script weekly is no prob, but how to post to the offline user is.

PLEASE help...

thanks Tzook
Janar Jürisson #
to tzook: That token you get from session must be saved somewhere so later your weekly script can access it and use it to post on token owners wall. I believe that's it. Haven't tried it for a while dough.

I hope it helps :)
No gravatar aivable
phil #
have you found a way to use more than one access token at a time in an array?

I am trying to create a cron that updates multiple users status' using the access tokens I have stored in mysql.

I feel that modifying something like this would be where to start:

//Retrieve user access_token from database
$results = mysql_query("SELECT access_token FROM demographic ORDER BY access_token ASC");
while($access_token_array = mysql_fetch_assoc($results)) {
$list_access_token[] = $access_token_array['access_token']; // to store results in an array
}
$comma_separated = implode(",", $list_access_token);
//print_r ($comma_separated);

//Array to post to wall
$post = array(
'access_token' => $comma_separated,
'message' => 'This message is posted with access token - ' . date('Y-m-d H:i:s')
);

//Actual post to wall
$facebook->api('/me/feed', 'POST', $post);

any suggestions would be appreciated.

thanks a lot.
No gravatar aivable
smiles #
I could I use this to post on the users wall weekly? I've looked EVERYWHERE and I just can't find anything close enough to help me :(

I considered using php if, [like if( thursday = post on wall, else don't] sort of thing. but It would have to be open to know wouldn't it?
Janar Jürisson #
To phil, I am not sure that you can do that.

To: smiles, Use cron for that.
No gravatar aivable
Filipi #
Good morning , sorry to my english.

I can post status in the wall, but when use cron not work... Already try everything and cannot to use cron for automatize. Can be anything permission? if not use cron work!

My code:


api_client->session_key = FB_SESSION;

$fetch = array('friends' =>
array('pattern' => '.*',
'query' => "select uid2 from friend where uid1={uid}"));

echo $facebook->api_client->admin_setAppProperties(array('preload_fql' => json_encode($fetch)));



$sql = $base ->query('SELECT * FROM wall WHERE DATE_FORMAT( data_agendada, "%H:%i" ) = DATE_FORMAT("' . date('Y-m-d H:i:s') . '", "%H:%i") ');



while ($result = $base ->tupla($sql)) {

echo $result ['text_facebook']."";

echo "sign in";


if ($facebook->api_client->stream_publish($resultado['text_faceboon]." Testing cron"))
echo "Added on test FB Wall";
}
} catch (Exception $e) {

echo $e . "";
}
?>
No gravatar aivable
Filipi #
Good morning , sorry to my english.

I can post status in the wall, but when use cron not work... Already try everything and cannot to use cron for automatize. Can be anything permission? if not use cron work!

My code:


api_client->session_key = FB_SESSION;

$fetch = array('friends' =>
array('pattern' => '.*',
'query' => "select uid2 from friend where uid1={uid}"));

echo $facebook->api_client->admin_setAppProperties(array('preload_fql' => json_encode($fetch)));



$sql = $base ->query('SELECT * FROM wall WHERE DATE_FORMAT( data_agendada, "%H:%i" ) = DATE_FORMAT("' . date('Y-m-d H:i:s') . '", "%H:%i") ');



while ($result = $base ->tupla($sql)) {

echo $result ['text_facebook']."";

echo "sign in";


if ($facebook->api_client->stream_publish($resultado['text_faceboon]." Testing cron"))
echo "Added on test FB Wall";
}
} catch (Exception $e) {

echo $e . "";
}
?>
No gravatar aivable
urvisha #
i m not getting $session..
No gravatar aivable
Urvisha #
can you put download link for php-sdk.
bcoz i am not getting $session .please help me.
Thnxx.
No gravatar aivable
S.Sivakumar #
Hi Janar,

I want to develop a simple gift app . When the user selects a friend and send a image . The selected image should be posted on the sender and receiver wall. Do u have any idea about this . It will be so useful for me please help if u know . Thanks in Advcance
No gravatar aivable
phil #
Heres how to do it with a cron job if you have the access tokens stored in a mysql database:

$token,
'message' => 'message here.'
);

//Actual Post
$facebook->api('/me/feed', 'POST', $post);
}
?>
No gravatar aivable
Peter #
I have your last script being executed, token coming from an MYSQL database. Unfortunately I get "PHP Fatal Error: Uncaught OAuthException: Bad signature thrown in php-sdk/base_facebook.php on line 998". Can't find anything on Google that helps. Can you give me a hint please? Thanks!
No gravatar aivable
hai #
hi when i use the "me" it means that i am trying to post on my wall

i manged it to work only for posting in my wall ??

can you help me ??
Janar #
to hai: Not exactly. You are using access token to tell API whose wall to post.
No gravatar aivable
hai #
ok so i will use this sentex but

where do i put the code (php script)

in cron_job ?

tnx for the help
No gravatar aivable
Lukas Kupka #
Janar pls explain me the access token purpose. You wrote "You are using access token to tell API whose wall to post." but i thought that the AAAA in "/AAAA/feed', 'POST', array ...." tells api whose wall to post. For posting on users' wall i use access_token taken from this url:

https://graph.facebook.com/oauth/access_token?client_id=" . Conf::$FB_APP_ID . "&client_secret=" . Conf::$FB_APP_SECRET . "&grant_type=client_credentials
Janar #
I think my explanation is little bit confusing. What I mean fallowing. If I want to post on users wall when he is not interacting with my application currently, I have to use access_token provided earlier by that user. There is no need for "/AAAA/feed" where AAAA is user because when using that token given earlier, API acts like being that user itself. I can't explain it better at moment. Maybe it helps.
No gravatar aivable
Lukas Kupka #
I think I've got it. You explain me clearly what i want you to and really appreciate what you've done here for fb developers. THNX
Fabrizio #
Hi Janar,


very helpful! I am going to store the token in DB but I cannot find what the length is... do you know if there is a maximum access_token length stated in the OAuth 2.0 specification. I haven't found it yet.
Janar jürisson #
Actually I don't know. And if I look around I only see same questions all over the google. Don't know is it true, but here it says its not defined at all. I currently use varchar 255 @ MySql (since there has not been problems with that), but sure I should investigate that someday myself too.
No gravatar aivable
Say Hong TAN #
Hi Janar! Great tutorial!

I was going through the code but found that the 'cookie' parameter needs to be disabled, otherwise authenticating with facebook doesn't work.


'application ID',
'secret' => 'application secret',
// 'cookie' => true,
));
?>

I'm using Facebook PHP SDK 3.0.1
drooh #
Janar, thank you so so much for writing such an easy to understand tutorial. I really wish that everything out there was this easy to follow. I spent so much time going through other tutorials and they were way to complex.

Have you made a tut similar to this for twitter and php?
No gravatar aivable
bRy #
Hi Janar, I would like to post to a fan page. How can this be done?
Janar jürisson #
to Drooh: Thank you. I haven't done Twitter or PHP tutorials :)

to bRy:
I haven't done it myself yet. So you probably are better off by googling around a bit. I am almost sure it is very much discussed topic.
No gravatar aivable
Leandro #
hi, thank you very much for the post!
I have a problem ..

$ token = array (
'access_token' => 'TOKEN HERE'
);
$ userdata = $ facebook-> api ('/ me', 'GET', $ token);


This code creates me a 500 error on the server, it can be?
I'm trying to get information from a user with a token.

Thanks
No gravatar aivable
Arjan #
great tutorial. But I found out something strange when you post a link to your wall, while using the offline_access permission.

The link is posted on the wall, no problem there. But when you click on it nothing will happen. If another FB user is clicking on that link facebook is asking that user to give offline access to the app?

Does anybody have an idea how to prefend this?
Janar #
to Arjan: I find it not strange. It's like it should be. If you are talking about "via your app name" link?

Its up to you what you display for user who accesses your application. For people who have not allowed you app yet it will ask permissions and its normal.
No gravatar aivable
fb_beginner #
is it possible, to post on user's wall by using the app/page id? (like, my app will post on the user's wall...)
Janar #
to fb_beginner:

Yes- trough app it's possible. Current blog post is one example of that.

But trough page- as far as I know it's not possible. Also not seeing such token @ http://developers.facebook.com/docs/reference/api/permissions/
Mohammad Shahid #
It is strange for me that we can post offline on facebook wall.

very easy and useful post, thanks alot :)
No gravatar aivable
Yuri Cauna Robles #
Muchas gracias! Todo muy Claro! gracias n.n
Thanks! all it's Clear!
No gravatar aivable
masoom #
'my ap id',
'secret' => 'my sec',
'cookie' => true,
);
$facebook = new Facebook($config);
$facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'scope' => 'offline_access,publish_stream'
));

$user = $facebook->getUser();
if($user){
$mytoken=$facebook->getAccessToken();
}
$post = array(
'access_token' => $mytoken,
'message' => 'This message is posted with access token - ' . date('Y-m-d H:i:s')
);
$res = $facebook->api('/me/feed', 'POST', $post);
?>


Hello this is my code but its not run while i use offline_access ,but i get the access token its mean the $facebook->api('/me/feed', 'POST', $post) does't work please someone help me its urgent
Janar #
Your question is confusing. It's hard to tell what is your exact problem here. But I see you are not doing anything with string returned by getLoginUrl() method. You should create a link with that URL and fallow it.
No gravatar aivable
Petr #
Hello,
I would like to post on the company wall but the script still posting on my wall. The company wall is still empty.

How can i grand privilegies to to application, to posting on my wall? I filled /COMPANY_ID/feed (replaced COMPANY_ID), but still posting on my wall.

Could you give me some help please?

Thank you
Janar #
Check out my comment @ http://eagerfish.eu/using-facebook-off-line-access-to-post-on-users-wall/#comment-227
No gravatar aivable
masoom #
hello friend i want to auto wall post by using cron job in my previous code that is working for offline_access,there my wall posting does't work can u tell me how i get specific error through from facebook that helps me about the problem
No gravatar aivable
masoom #
hello janar plz send me auto wall posting complete code where i just change my appid and secrete and its run through cron,if u r easy then plz send me by email on masoom.ego@gmail.com
No gravatar aivable
masoom #
hello my all working is done but still post method does't work while i get offline_access and also get the access token..
here is my code
$facebook->api('/me/feed', 'POST',array('access_token'=>$access_token,'link' => 'www.funmx.com','message' => 'myposting'));
No gravatar aivable
Petr (from 13 January 2012 19:48) #
Hello,

I looked on the autorization.
Everythink is ok, but when I admin more company pages, I dont want to grand privileges to all this pages.
Is it possible to choose one, where can I post on the wall?

Thank you much
No gravatar aivable
harold #
hello experts,

im getting errors on my log message
OAuthException: Error validating access token: Session has expired at unix time (number) . The current unix time is (number).
ive readarticles about this and i found out FB team are makingchanges with there apps. and ive read, the error is when a user is offline
everytime i make a job i get this
how can i edit FB apps so it can post to offline users
thanks
No gravatar aivable
Andras #
Hi the code works fine, but my only the problem is I can see only the wall post if I go to my friend profile, it doesn't appear in the news, it does in the right corner but not in the main news, any idea why? I have tried everything now I just don't know what could be the problem.
No gravatar aivable
vural #
thanks for admin
No gravatar aivable
zzz #
Hi. I place a message, but no one but me sees it. Settings for the application are "available"
No gravatar aivable
hasan #
Hi!
The user enters the application.
sample access_token: EYDMJF54FGDFG

Facebook user closes the session and re-enters.
new sample access_token: JGJGJ6FGHFB

Why is it changing?
No gravatar aivable
Janar #
I suppose it's how it works, but does access tokens itself work? Is it causing problems?
No gravatar aivable
Mohamed Tair #
Excellently described. Thank you very much for post
No gravatar aivable
Sazid Ali #
Hi,
Can anybody help me please..???
I have a fan page on the facebook- https://www.facebook.com/YouarewithmeDear

and I want to upload a gif/animated picture on the wall,
how is it possible,Can any body tell me please.

Here is a example of animated pictures on the wall
https://www.facebook.com/pogo.official


Can anybody help me please??/

Is the possible with live stream, ui:fb stream
or how?

Thanks in advance
Janar #
Your question/comment is so messed up. There is no concrete question to answer to.
No gravatar aivable
Sazid Ali #
Thanks for your feedback.

actually I want to post Gif/animated picture on the wall of a fan page(the name of the page is https://www.facebook.com/YouarewithmeDear) so anybody can Like and share them .
how is it possible to post any Gif/animated picture on wall, can you please tell me. Because directly we can not upload the GIF/Animated picture on the fan page wall.

I saw on one page 3 days ago(Here you can see-https://www.facebook.com/2share,
with this heading-
There is a cat, who is moving his face left and right.

hahaha x'D HipHop Cat :D
Share LOL! )

when i select this picture and i saw selection source,
this is showing in html or may be java scrip

hahaha x'D HipHop Cat :D

hahaha x'D HipHop Cat :D

Janar #
I can't answer that. I don't want to be mean, but this question belong to some forum instead. I find this totally irrelative to current post topic.

You should google your problem instead. Doesn't that answer your question?
http://melroz.blogspot.com/2011/05/loading-animated-gif-onto-your-wall-in.html
No gravatar aivable
Sazid Ali #
I am really sorry that i am not explaining you well.

https://www.facebook.com/pages/Joel-Nagy-com/126165237425344?sk=app_7146470109.
this is an animated picture, If i want to post it to my page's wall with my page's link .how i can add this?


I listen from my friend that there is a some option on facebook developer page like- ui:fb stream, feed, live stream etc, where i can creat an application for gif/animation pictures.


please tell me how i can add the gif/animated picture on the wall of my fan page to show my page's fan.
Janar #
I said that I don't know how. Also this highly irrelevant to current topic. You should post that question in some forum instead.
No gravatar aivable
Fayaz97 #
Hi!

Great stuff!

If I want to get status from the wall of a fan of my app.

How can I do?

instead of :
$userdata = $facebook->api('/me', 'GET', $token);

do:
$userdata = $facebook->api('ID OF THE FAN', 'GET', $token);

??

I guess there will be a trouble with the token?
Because the token will be provide for me not for the ID OF THE FAN I want?

Hope you have the answer!!

Cheers
Janar #
If I understand you are asking same question as one visitor asked here @ http://eagerfish.eu/using-facebook-off-line-access-to-post-on-users-wall/#comment-227

Answer is still same.
No gravatar aivable
Fayaz97 #
Hey Janar,

No it's not the same question at all.
I didn't want to post a feed.
I wanted to GET status with my app from people who like my appli.
I had the answer from Facebook.
It's possible to get the message from the fan page linked with an appli BUT NOT from the wall of others.
That means I can't do what I wanted to... :-(
No gravatar aivable
hardik tanna #
nice!!!!!!!!!!!!!!
No gravatar aivable
yusuf handdian #
Very nice info, Thank you so much
No gravatar aivable
HAYS TOME #
I want to ask how to send requests by PHP
And how to show it to the user and its relation to these requests
No gravatar aivable
smylin s #
Thank you so much. It supported me lot.
No gravatar aivable
Shashank #
hey Janar. I used your code and its working fine till the application load and i get an "API Call Failed" error.
Can you please tell me what exactly does it mean and how to resolve it?
janar #
Switch this part of the code:

die("API call failed");

to this:
die( "API call failed: ". $e->getMessage() );

to get what error/exception happened.
No gravatar aivable
Shashank #
this is the error I am getting now- "API call failed: error setting certificate verify locations: CAfile: C:\xampp\htdocs/fb_ca_chain_bundle.crt CApath: none"
No gravatar aivable
Shashank #
Resolved this. My fb_ca_chain_bundle.crt was in the src folder and i did not specify the path.
Another question, can I use the derived offline token to post on people's wall?
How to do that?
Janar #
If that token you are taking from database has enough permissions and not expired yet- yes it's possible.
Check out the part "Using token for posting"
for example.
No gravatar aivable
Gourab Singha #
$facebook->setAccessToken($_REQUEST['access_token']);

$post = array(
'message' => 'This message is posted with access token - ' . date('Y-m-d H:i:s')
);

//and make the request
$response = $facebook->api('/me/feed', 'POST', $post);

This code works perfect
No gravatar aivable
Gourab Singha #
Please disable "Remove offline_access permission:
Disabled" so it works. else not.
No gravatar aivable
Gourab Singha #
from fb apps advance setting.
No gravatar aivable
Cazacu #
I see the following error: Error Validating access token: The session is invalid Because the user logged out.
No gravatar aivable
Ryan #
I had the offline access token but couldn't figure out how to post. As a new facebook developer and after days of searching around, your 5 SIMPLE lines of code actually did it! Not only does it work perfectly, I've actually gained more knowledge and experience with facebook apps!
Thanks!
No gravatar aivable
sonu sindhu #
Thanks buddy save my energy and time
No gravatar aivable
Prachi #
Hi

Please help!!
When I am posting via my app to a page,then it is only visible to me,not even manager of the page able to view.
Janar #
I am not able to answer that at moment.
No gravatar aivable
Mohamed Javid Khan #
Helllo I face some issues in Facebook wall posting ...i can post my friends wall using graph api but i cant post permissioned user . Permission user means that user register facebook through our site ...

can we send that permission user wall also ?
No gravatar aivable
Etom #
Hi,sorry to my english.

As you said, I post a request using the following codes:
function publishCustomAction($facebook,$url,$action,$fb_id,$access_token) {
$app_namespace=[my namespace];
$post=array('nikeshoes' => $url,'access_token' => $access_token,'message' => 'This message is posted with access token ');
$ret_obj = $facebook->api('/'.$fb_id.'/'.$app_namespace.':'.$action, 'post', $post);
return $ret_obj['id'];
}
But I got this error:

OAuthException: An active access token must be used to query information about the current user.

The access_token and fb_id is get from mysql database.

I have not idea why it happened.

help me

Thx
Janar #
Mohamed Javid Khan: Check what fails. What exception you receive when trying to post. Are those page user giving you "offline" access at all? Do you save those tokens and so on. I can't guess what is your situation exactly so you should debug it using google if stuck.


Etom: As your program states, there is problem with given token. Once again I can't guess what is wrong because there can be various reasons that could generate this outcome. I don't know what you have done. Where you got those tokens? Did they included "offline_access". Maybe user changed it's facebook password - and so on.

Generally you should reauthorize the user. Preferably you should use new way of doing that explained here - http://developers.facebook.com/roadmap/offline-access-removal/ "offline_access" is deprecated and should not to be used anymore.

Try debugging with help of google also.
No gravatar aivable
Mohamed javid Khan #
Thanks for reply . Actually my problem is not related to offline access ... When i am trying to post user wall at that time i cant get any error messages .That users already give permission through apps .. He is not friends just they allowed post user walls
No gravatar aivable
Etom #
Thanks for reply .

I tested it using my FB account. and the offline access permission is required while login in my website with FB account.

Access token was written into mysql database after login:

$access_token=$facebook->getAccessToken();

I think the access token is effective because I got the same access token when I login and reauthorize again.
No gravatar aivable
Etom #
I found the reason myself. Here is the correct codes:
function publishCustomAction($facebook,$url,$action,$fb_id) {
$app_namespace='...';

$post=array('my object' => $url,'message' => 'This message is posted with access token ');
//var_dump($post);
$ret_obj = $facebook->api('/'.$fb_id.'/'.$app_namespace.':'.$action, 'post', $post);
return $ret_obj['id'];
}


$facebook->setAccessToken($access_token);
$story_id = publishCustomAction($facebook,$url,$action,$fb_id);
No gravatar aivable
rajkumar #
I am getting this error while running the code

Fatal error: Call to undefined method Facebook::getSession()

Unable to fix this, Please help me. Thanks in advance
No gravatar aivable
amr #
can we use this with wordpress
when a new post added publish the new post to users's of facebook application wall
No gravatar aivable
vivek #
hii i want to fetch the acess token from my database to post how to do that
No gravatar aivable
OmniTech Support Ripoff #
I think as of now we can post on the user’s wall, if she/he is not logged in. It’s the same as the existing situation. Is there anything new in it? I don’t think so. I doubt I am not understanding it in the correct way.
No gravatar aivable
2012canadagoosejakker.blogspot.com/ #
I had to sit up all night writing the report.The road divides here.I was alone,but not lonely.I don't care where we go as long as we don't have to stand in line.Just for entertainment.I'm afraid I have some rather bad news for you.I'm afraid I have some rather bad news for you.First come first served.I'm lost.They rode their respective bikes.
No gravatar aivable
Anil Singh #
Thank you very much for script.
Joseph #
I used the offline access to post as one of my pages, with cronjobs. Now it is not working.

Is there any way to be able to post offline?
Janar #
I would start by finding out why it's not working anymore. Then you can start fixing it.

But yes- there is a way - there is a link top of this post.
Joseph #
Here is their message:

{
"error": {
"message": "This authorization code has expired.",
"type": "OAuthException",
"code": 100
}
}
No gravatar aivable
ankita #
hey,
i understand that code...
bt found error...
help me...
Fatal error: Uncaught OAuthException: Error validating access token: The session is invalid because the user logged out. thrown in /home/addonn79/public_html/dev/tutorial/Amruta/offline post/src/base_facebook.php on line 1238
No gravatar aivable
Aakash #
I am having the same problem as ankita.. getting the same error.. any help?
No gravatar aivable
Ketaki #
Me too. I got long-lived access token exchanged for short-lived but if I log out....token becomes invalid.
No gravatar aivable
Kamran Ismail #
Thanks it solves my problem
No gravatar aivable
nat #
Fatal error: Call to undefined method Facebook::getSession() on line 27

$session = $facebook->getSession();

:(
No gravatar aivable
anonymous #
thanks, strangely it worked
No gravatar aivable
Phyu Phyu #
Hi, I used facebook-php-sdk v3.0.0 and it worked well. But, now when I upload a news without picture, it only show title and not include others, description, url,etc. Please reply me. Thanks.
No gravatar aivable
karthik #
Hi this script is working latest facebook api ?
I am co-founder of web/media studio GIVE me. and (android)developer at start-up named Choco. Read my about page to learn more.