Reputation: 3500
I've been reading a lot in the last few days, and I'm sure that I've been learning a lot. All this due Facebook documentation being spread (in the bad sense) all over the web, making people looking for the information and trying a lot of things.
I've done some stuff like:
So, I've thought about creating a kind of an automatic poster to pages. But, imagine what. We need Access Tokens to that, those that won't expire.
Ok, no problem. From what I've been reading App Access Tokens take care of that, and then I can run a cron with the script!
But how it is supposed to run the posting with the Access Token?
Currently, with the user token, I was using this code if the id of the logged in user could be retrieved.
FB.api('/<?=$album_id?>/photos?access_token=<?=$fanpage_token?>', 'post', {
message: ementa,
url: selected_image
}, function(response) {
if (!response || response.error) {
alert('Falhou a publicar a ementa com imagem');
} else {
alert('Page Post ID: ' + response.id);
}
});
I've got the fan page token manually from the Graph API Explorer, because this is just going to be used by the cronjob.
Album ID i've got previously too.
How could I use this with an App Token?
Thanks!
Upvotes: 2
Views: 3890
Reputation: 3500
After long days of research on Facebook Application API usage, I've finally discovered thanks to cbaclig that Applications can't control some stuff, and do just have permissions to do stuff like Check Page Insights, Making Real-Time Updates, and some stuff like that.
I discovered this in this link.
Quoting the answer in the link (just in case that it goes offline):
It seems like the search method requires an actual user access token, not just an application access token like you're using in your example. I tried the same query with a logged-in user's access token, and it worked fine. The first examples on https://github.com/arsduo/koala/wiki/OAuth describe different ways of getting a user's access token (via OAuth redirects, the Javascript SDK, etc.) which you should be able to use to make your queries.
In general, the app access token is only used for application-specific things, like getting your app's insight data, registering real-time updates, generating test user's, etc.
Let us know if that helps!
EDIT 11/11/12: I've finally discovered that page access tokens could have access to publish_stream and manage_pages, that would allow them to publish with an expiry-never access token.
You need to get a Fan Page access token using an Extended Access Token of the user. That one will never expire and you could then use it to make requests as the page forever.
Upvotes: 0
Reputation: 2370
First of all, you can get extended user token (that lasts for 60 days) in php
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => APP_SECRET,
'fileUpload' => true
));
$facebook->setExtendedAccessToken();
Then $facebook->getAccessToken()
and store it to Database;
After that, if you wish to post something to the appropriate users wall, create $facebook object, set existing access token and do the things...
$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $appSecret,
'fileUpload' => true
));
//set token
$facebook->setAccessToken($fbAccessToken);
$facebook->api('/me/photos','post', $data);
This will autonomously work with a cron job.
Upvotes: 4