使用 Facebook Graph API 获取公共页面状态,无需访问令牌

发布于 2024-12-07 21:36:28 字数 653 浏览 0 评论 0原文

我正在尝试使用 Facebook Graph API 从公共页面获取最新状态,比方说 http://www .facebook.com/microsoft

根据 http://developers.facebook.com/tools/explorer/?method=GET&path=microsoft%2Fstatuses - 我需要访问令牌。由于微软页面是“公开的”,这肯定是这样吗?如果没有访问令牌,我是否无法访问这些公共状态?

如果是这种情况,为我的网站创建访问令牌的正确方法是什么?我有一个应用程序 ID,但是 http://developers.facebook.com/docs/ 上的所有示例身份验证/ 描述处理用户登录。我只想获取 Microsoft 页面上的最新状态更新并将其显示在我的网站上。

I'm trying to use the Facebook Graph API to get the latest status from a public page, let's say http://www.facebook.com/microsoft

According to http://developers.facebook.com/tools/explorer/?method=GET&path=microsoft%2Fstatuses - I need an access token. As the Microsoft page is 'public', is this definitely the case? Is there no way for me to access these public status' without an access token?

If this is the case, how is the correct method of creating an access token for my website? I have an App ID, however all of the examples at http://developers.facebook.com/docs/authentication/ describe handling user login. I simply want to get the latest status update on the Microsoft page and display it on my site.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

迷雾森÷林ヴ 2024-12-14 21:36:28

这是设计使然。一旦可以从公共页面获取最新状态而无需访问令牌。为了阻止未经识别的匿名访问 API,这一点已被更改。您可以使用图形 API 通过以下调用获取应用程序的访问令牌(如果您没有为您的网站设置 Facebook 应用程序 - 您应该创建它):

https://graph.facebook.com/oauth/access_token?
client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&
grant_type=client_credentials  

这称为应用程序访问令牌。然后,您可以使用上面的应用程序访问令牌继续进行实际的 API 调用。

希望这有帮助

This is by design. Once it was possible to fetch the latest status from a public page without access token. That was changed in order to block unidentified anonymous access to the API. You can get an access token for the application (if you don't have a Facebook application set for your website - you should create it) with the following call using graph API:

https://graph.facebook.com/oauth/access_token?
client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&
grant_type=client_credentials  

This is called App Access Token. Then you proceed with the actual API call using the app access token from above.

hope this helps

御守 2024-12-14 21:36:28

您可以使用 AppID 和密钥来获取任何页面的公开帖子/提要。这样您就不需要获取访问令牌。像下面这样称呼它。

https://graph.facebook.com/PAGE-ID/feed?access_token=APP-ID|APP-SECRET

并获得职位。

https://graph.facebook.com/PAGE-ID/posts?access_token=APP-ID|APP-SECRET

You can use AppID and Secret key to get the public posts/feed of any page. This way you don't need to get the access-token. Call it like below.

https://graph.facebook.com/PAGE-ID/feed?access_token=APP-ID|APP-SECRET

And to get posts.

https://graph.facebook.com/PAGE-ID/posts?access_token=APP-ID|APP-SECRET
离笑几人歌 2024-12-14 21:36:28

如果没有访问令牌来读取公共页面状态,则无法再使用 Facebook Graph API,这在 Facebook API 权限中称为页面公共内容访问。访问令牌甚至还不够。您必须将 appsecret_proof 与访问令牌一起使用才能验证您是否是合法用户。 https://developers.facebook .com/blog/post/v2/2018/12/10/verification-for-individual-developers/
如果您是个人开发人员,您可以访问三页数据(有限),除非您拥有商业应用程序。

It's no more possible to use Facebook Graph API without access token for reading public page statuses, what is called Page Public Content Access in Facebook API permissions. Access token even is not enough. You have to use appsecret_proof along with the access token in order to validate that you are the legitimate user. https://developers.facebook.com/blog/post/v2/2018/12/10/verification-for-individual-developers/.
If you are individual developer, you have access to three pages of the data (limited), unless you own a business app.

忘你却要生生世世 2024-12-14 21:36:28

您只需请求浏览器请求的站点,然后从 HTML 中提取帖子即可获取帖子。

在 NodeJS 中,您可以这样做:

// npm i request cheerio request-promise-native
const rp = require('request-promise-native'); // requires installation of `request`
const cheerio = require('cheerio');

function GetFbPosts(pageUrl) {
    const requestOptions = {
        url: pageUrl,
        headers: {
            'User-Agent': 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0'
        }
    };
    return rp.get(requestOptions).then( postsHtml => {
        const $ = cheerio.load(postsHtml);
        const timeLinePostEls = $('.userContent').map((i,el)=>$(el)).get();
        const posts = timeLinePostEls.map(post=>{
            return {
                message: post.html(),
                created_at: post.parents('.userContentWrapper').find('.timestampContent').html()
            }
        });
        return posts;
    });
}
GetFbPosts('https://www.facebook.com/pg/officialstackoverflow/posts/').then(posts=>{
    // Log all posts
    for (const post of posts) {
        console.log(post.created_at, post.message);
    }
});

有关如何检索 20 多个帖子的更多信息和示例,请参阅:https://stackoverflow .com/a/54267937/2879085

You can get the posts by simply requesting the site that your browser would request and then extracting the posts from the HTML.

In NodeJS you can do it like this:

// npm i request cheerio request-promise-native
const rp = require('request-promise-native'); // requires installation of `request`
const cheerio = require('cheerio');

function GetFbPosts(pageUrl) {
    const requestOptions = {
        url: pageUrl,
        headers: {
            'User-Agent': 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0'
        }
    };
    return rp.get(requestOptions).then( postsHtml => {
        const $ = cheerio.load(postsHtml);
        const timeLinePostEls = $('.userContent').map((i,el)=>$(el)).get();
        const posts = timeLinePostEls.map(post=>{
            return {
                message: post.html(),
                created_at: post.parents('.userContentWrapper').find('.timestampContent').html()
            }
        });
        return posts;
    });
}
GetFbPosts('https://www.facebook.com/pg/officialstackoverflow/posts/').then(posts=>{
    // Log all posts
    for (const post of posts) {
        console.log(post.created_at, post.message);
    }
});

For more information and an example of how to retrieve more than 20 posts see: https://stackoverflow.com/a/54267937/2879085

久随 2024-12-14 21:36:28

几周来我有一个类似的用例,我使用了这个 API:

https: //rapidapi.com/axesso/api/axesso-facebook-data-service/

我可以在几分钟内获取所有帖子和评论,对我来说效果很好。

I had a similar use case for some weeks and I used this API:

https://rapidapi.com/axesso/api/axesso-facebook-data-service/

I could fetch all posts and comments in some minutes, worked quite well for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文