Facebook - how to get permanent user access token [duplicate]

风流意气都作罢 提交于 2019-12-05 17:47:45

I also wanted to access the data without creating an app. I tried a lot of things, but finally I had to create for app just for the sake of it. So you would have to create an app.

Also, If you see the developers website, it says that they removed the "offline_access " permission in December 2012. See here: https://developers.facebook.com/roadmap/offline-access-removal/ . So, it was then they brought the long-lived access token. They also say and I quote, " If you would like to refresh a still valid long-lived access_token, you will have to get a new short-lived user access_token first and then call the same endpoint below."

So you would have to get the short term access token again and get the long-lived token using the short lived token. To get the long term access token, You may send a HTTP request like this:

var short_access_token; //Get this
var xhr = new XMLHttpRequest();
var f_url = "https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id=CLIENT_ID&client_secret=APP_CLIENT_SECRET&fb_exchange_token="+short_access_token;

xhr.open("GET", f_url , true);
xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {
        obj = xhr.responseText;
        long_token =  obj.split('=')[1].split('&')[0];
    }
}
xhr.send();

Hope it helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!