Facebook graph API - permanent lived access token - facebook

I'm using Facebook graph API to show media on my website via
https://graph.facebook.com/v13.0/{page-id}/posts?fields=id,created_time,picture,message,permalink_url,full_picture&access_token={access-token}
I followed all steps and I generated a long lived token for 60 days, but there is a way to make a permanent token ?
I saw that there was a possibility with facebook business, but is there another way?
thanks

Related

Automatic post to my facebook page from Node.js server

I have a Node.js server running a social network site and I also have a facebook page for that site. For certain actions performed by users on my site, I want to post details on the facebook page of my app.
I referred to Thuzi facebook node sdk here on how to post to facebook wall. However, it requires app id, app secret and a temporary access token. App id and app secret are constant so I can put them somewhere in my config file and use from there. But how do I get the access token without any interaction from front-end ? All posts will be published by our app only and that too on our own page. I just want this to be triggered by the end user's actions. Any help ?
I am using Sails.js framework btw.
You would need to use an Extended Page Token for that, you only need to create it once and it will stay valid forever. And you will post "as Page" with a Page Token. How to get an Extended Page Token:
Create an App
Use the Graph API Explorer to generate a User Access Token (by authorizing the App with the manage_pages and publish_actions permission)
Extend the User Access Token (valid for 60 days)
Request an Extended Page Token by calling /me/accounts
Store that Extended Page Token on your server and use it for posting on the Page wall.
Here are some additional resources, explaining everything in detail:
https://developers.facebook.com/docs/facebook-login/access-tokens/
https://developers.facebook.com/docs/graph-api/reference/v2.1/page/feed
http://www.devils-heaven.com/facebook-access-tokens/
http://www.devils-heaven.com/extended-page-access-tokens-curl/
I am also digging more in to this nowdays As I am working on a node module for this.
Till now I got to know that we can create a temporary access_token and we can than extend that token upto max 60 days.
For this after getting temporary token you need to make a call to this url to get a access token with 60 days validity.
https://graph.facebook.com/oauth/access_token?client_id=&client_secret=&grant_type=fb_exchange_token&fb_exchange_token=

Get user access token from Graph Api Explore facebook and extend it

I know how to get short-term user access token then extend it to long-term access token (facebook) when i have my own app id and app secret. But now I want to get and extend the access token provided by Graph Api Explorer. How can I do it ?
If we do it manually, we get an access token from Graph Api Explorer but its short term and will expires in about 1 hours, how can I make it a long-term access token?
This is not possible. To extend the Access Tokens, you must utilize an app_id as well as an app_secret. I assume you don't have the app_secret of the Graph Explorer, so this might get difficult.
See
https://developers.facebook.com/docs/facebook-login/access-tokens#extending
I still have this issue and Tobi not understood the problem.
The Facebook Access Tokens are really problematic most of times and this is one of the bigger issue.
I have a facebook stream plugin where user can show their personal profile posts.
But the only access token that work is the one generated by Graph API Explorer and this can not be extended. Any other access token associated to an APP will not work.
Is incredible that Facebook not have a tool to allow users to generate an access token for access their personal informations.
Currently there is not any working solution. Incredible.

"The access token does not belong to application" Trying to generate long lived Access Token

I am having problems generating long lived Access Token to update Facebook page from my desktop application.
I created a Facebook App associated with my Facebook user and stored it's app id and secret.
I created a facebook page associated with my Facebook user account.
I can create a short lived (60 minutes) access token for my app.
My desktop application is able to post to my Facebook page using the short lived access token. However, this only lasts 60 seconds and is therefore impractical.
I have been trying to generate a long lived access token using the guidance here:
Request a Page Access Token in C# SDK
However I receive an error:
"The access token does not belong to application XXXXXXXXXXXXXXX"
When I try enter my short lived access token in the debug tool the box, it confirms that the access token is mine BUT it shows a different app id.
Where does this different app id come from? I only have one Facebook app defined.
I think I might be missing a fundamental point here.
Many thanks for any help you can give.
Go back to the Graph API Explorer where you generated the token.
Make sure that you selected your app from the drop-down at the top where it says "Application[?]"
If you don't it defaults to 'Graph API Explorer' and that will be of no use to you. Once you get the token made for the correct app, try again using this URL:
(replace NNNN with the correct data)
https://graph.facebook.com/oauth/access_token?client_id=NNNN&client_secret=NNNN&grant_type=fb_exchange_token&fb_exchange_token=NNNN
Steps are:
Generate app token with the following Graph API call:
GET /oauth/access_token?
client_id={app-id}
&client_secret={app-secret}
&grant_type=client_credentials
Exchange received token for a long-lived token (60 days) with the following Graph API call:
GET /oauth/access_token?
grant_type=fb_exchange_token&
client_id={app-id}&
client_secret={app-secret}&
fb_exchange_token={short-lived-token}
that will give you long-lived token associated with your app. If you want to post on the page AS THE PAGE, then you need to get Page access token - see here for more details: https://developers.facebook.com/docs/facebook-login/access-tokens/#pagetokens
Authenticate the user and request the manage_pages permission
Get the list of pages the user manages from (1): https://graph.facebook.com/me/accounts?access_token=USER_ACCESS_TOKEN
Parse the list and get the token - and use it to post to the feed.
you will do (1) in graph API explorer - and you will get user token. Then insert that token into URL in (2) - and you will see all your pages and corresponding token. Take the one you need and use it in your C# code to upload images.

How to get permanent access token in graph API

I created an APP on Facebook and using graph API explorer, I selected my app from app drop down box, requested access token with manage_pages, offline_access and publish_stream permissions.
Using this access token, I was successfully able to post message on page using restfb APIs but when I log out, it starts throwing The session is invalid error.
I read on few posts that offline_access is deprecated. Could someone tell me how to obtain permanent access token?
Thanks
Looking at the docs at: https://developers.facebook.com/roadmap/offline-access-removal/ this is no longer possible.
Desktop applications will not be able to extend the life of an
existing access_token and the user must login to facebook once the
token has expired.
Otherwise, it is possible to request an access token with a longer expiration. Here are the directions: https://developers.facebook.com/roadmap/offline-access-removal/#extend_token
What kind of Access Token do you need? There are three kinds, User AT, App AT and Page AT.
If you want User AT, it seems you are out of luck. I don't think it's possible anymore. You can only get to 60 days. However, if you need Page AT, you can get a permanent one. The difference is, Page Access Token only has access to a single facebook page.
Basically you need to get User Access Token first, with manage_pages permission. When you have one, you have to look at /{pageId}?fields=access_token for your page's id in Graph API.
For more info look at: facebook: permanent Page Access Token?
you will not get any permanent access token as Facebook developer blog explains. you will be given 60 days long lived access token. Before the expiration Facebook will notify you about the expiry and then you can renew it or you can build your own custom control to get the notification on token expiration which you can fetch from Facebook API.

Post to Fan Page without offline_access using Graph API?

I need to make an web application to manage posts, when a post is made sometimes I should post a brief promotional message one of the company fanpages on facebook (depending on criteria on the post).
This is possible right now using the offline_access permission: create application A, request the manage_pages, offline_access, publish_stream permissions and with that access token you can connect when you want to the graph api and post to the page.
Since offline_access is being deprecated and is going to be removed in May 2012 I was wondering how it would be possible to post to different pages of the company.
I can't implement any of the OAuth authentication mechanisms since the final user that uses the web application will not have access to the fb account that is page administrator and the posting to facebook should happen in a backend process not interacting with the user.
A workaround I found is to post to the page by posting on the admin user stream and tagging the page (that would only require publish_stream), but the Graph API is bugged and doesn't allow you to tag in posts. In code (Ruby + Koala) it would be something like this:
oauth = Koala::Facebook::OAuth.new("app-key", "app-secret", nil)
api = Koala::Facebook::API.new(oauth.get_app_access_token)
api.put_wall_post("message #[page-id:1:page-name]", {}, "admin-user")
The only problem is a bug in the facebook API prevents you from tagging stuff in posts to your stream.
Is this kind of model not going to be supported anymore? Anyone knows of any workaround?
You can increase 2 table columns in your app namely short_access_token & long_access_token.
Once user authenticates your app, an access token is generated, store it in short_access_token. Then pass this access token to:
https://graph.facebook.com/oauth/access_token?
client_id=APP_ID& client_secret=APP_SECRET& grant_type=fb_exchange_token& fb_exchange_token=EXISTING_ACCESS_TOKEN
Once you run this, an access token with 60 days validity will be generated. Store it in long_access_token. Now, use this long_access_token for 60 days.
You can add another condition where if the long_access_token was generated more than 30 days ago, just take the short_access_token and generate a new lon_access_token.
You can generate long lived access token only once a day i.e. the first time. Use this long lived access token to manage paes (if you've already got the permission).
Ref: https://developers.facebook.com/roadmap/offline-access-removal/
The only workaround you have is to give the app user page administrator access to the various pages, so when you do post to the page's wall, it can be posted as the page rather than a post as the user. However, you will only be able to extend a "valid" user access token to 60 days per Facebook's new rules. But with that 60 day user token, you can then get a 60 page access token, so you can post as the page to the page.
If you don't have the requirement of posting to the page as the page, then it's pretty simple to do it without attaching that user as a page admin. Just let them be a normal user.