Facebook - 如何获得永久用户访问令牌 [英] Facebook - how to get permanent user access token

查看:44
本文介绍了Facebook - 如何获得永久用户访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的公司有一个公司 Facebook 帐户,他们在不同的相册中发布活动照片.我的要求是从 facebook 相册中获取所有照片并显示在我们的公司网站上.我能够获取照片,但用户访问令牌的有效期仅为 60 天,这意味着每隔两个月我必须登录公司的公司 Facebook 帐户,重新生成令牌并在我的应用程序中更新令牌.

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 ?

我按照以下步骤操作: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= 我使用访问令牌调试器验证了令牌.令牌的有效期为 60 天.为了获取页面令牌,我使用了 url:graph.facebook.com/me/accounts?access_token= 我得到了我的应用程序页面的令牌.我在工具中验证了这个令牌,它的有效期只有 60 天

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

谢谢

推荐答案

我还想在不创建应用程序的情况下访问数据.我尝试了很多东西,但最终我不得不为它创建应用程序.所以你必须创建一个应用程序.

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.

此外,如果您看到开发者网站,它会说他们在 2012 年 12 月删除了offline_access"权限.请参阅此处:https://developers.facebook.com/roadmap/offline-access-removal/.因此,就在那时,他们带来了长期存在的访问令牌.他们还说并且我引用了,如果你想刷新一个仍然有效的长期访问令牌,你必须首先获得一个新的短期用户 access_token,然后在下面调用相同的端点."

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."

因此,您必须再次获取短期访问令牌并使用短期令牌获取长期令牌.要获得长期访问令牌,您可以发送这样的 HTTP 请求:

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();

希望能帮到你

这篇关于Facebook - 如何获得永久用户访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆