I have written an application that is able to write posts from the command line, to a particular users account. This, with the required permissions, is successfully posting messages with location and places information.
My next step was to upload images to a user account, but the problem is, I’m getting the following error:
A user access token is required to request this resource.
Now the script that does the API post, does not run from a browser, but rather as a Linux service daemon implemented with PHP. This script contains a game loop, that posts messages, and uploads photos to participants accounts at certain times throughout the day, simulating a holiday their profiles are attending.
So when calling BaseFacebook::getUser from my application script, I get a result of 0, which means, that BaseFacebook::getAccessToken will return an application access token, rather than a user access token.
I checked also, and noticed that the protected method BaseFacebook::getUserAccessToken doesn’t return a valid token, since the command line app has no session, and it has to post to separate different user accounts in succession, during the game loop.
As I mentioned, I am able to make posts, and even attach places to my posts, but is there a way to upload photos to different user accounts without requiring a user access token?
I understand that I can use offline_access, but this is being deprecated on 3 October 2012, which is the time when our clients application will already be running live.
The players/users of our app do however visit the application from time to time, so would it be possible to use a token from the browser, store it in our database, and just utilize that from the command line applciation?
That’s exactly the way to go.
And this document describes how to handle these token, how to get long-lived ones, etc. – https://developers.facebook.com/roadmap/offline-access-removal/
And https://developers.facebook.com/blog/post/2011/05/13/how-to–handle-expired-access-tokens/ is also something that one should have read.