Facebook - 如何获取永久用户访问令牌 [英] Facebook - how to get permanent user access token
问题描述
有没有办法生成永久访问令牌?或者还有什么办法在我的应用程序级别重新生成令牌(不显示登录对话框)?
有没有其他方法来获取照片而不创建应用程序? / p>
我遵循以下步骤: https://www.facebook.com/dialog/oauth?client_id=%3CCLIENT_ID%3E&scope=manage_pages&redirect_uri= 我从这个API调用得到代码。然后我得到如下令牌: https://graph.facebook.com/oauth/access_token?client_id = & redirect_uri =& client_secret =& code =我使用Access令牌调试器验证了令牌。令牌有效期为60天。要获取页面令牌,我使用url:graph.facebook.com/me/accounts?access_token=我得到了我的应用页面的令牌。我在工具中验证了这个标记,其有效期仅为60天
谢谢
我也想在不创建应用的情况下访问数据。我尝试了很多事情,但最终我不得不为了应用而创建应用程序。所以你必须创建一个应用程序。
另外,如果你看到开发者网站,它表示他们在2012年12月删除了offline_access权限。 https://developers.facebook.com/roadmap/offline-access-removal/。那么那就是他们带来了长久的访问令牌。他们也说,我引用:如果你想刷新一个仍然有效的长寿命access_token,你将必须先获得一个新的短期用户access_token,然后在下面调用相同的端点。
所以你必须再次获得短期访问令牌,并使用短命令令牌获取长命令的令牌。要获得长期访问令牌,您可以发送这样的HTTP请求:
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();
希望有帮助
My company has a corporate facebook account where they post event pics in different albums. My requirement is to get all the photos from facebook albums and show in our corporate website. I am able to fetch the photos but the user access token is valid only for 60 days which means every other two months i will have to login into company's corporate facebook account, regenerate the token and update the token in my application.
Is there any way to generate to permanent access token ? or is ther any way to regenerate the token at my application level ( without showing login dialog box) ?
is there any other way to fetch the photos without creating app ?
I followed following steps: https://www.facebook.com/dialog/oauth?client_id=%3CCLIENT_ID%3E&scope=manage_pages&redirect_uri= I got code from this API call. Then I got token as follows : https://graph.facebook.com/oauth/access_token?client_id=&redirect_uri=&client_secret=&code= I verified the token using Access token Debugger. Token is valid for 60 days. To get page token, i used url: graph.facebook.com/me/accounts?access_token= I got token for my app page. I verified this token in tool, Its valid only for 60 days
thanks
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
这篇关于Facebook - 如何获取永久用户访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!