在不强制用户登录/允许的情况下嵌入公共 Facebook 页面的活动源 [英] Embed activity feed of a public Facebook page without forcing user to login/allow

查看:21
本文介绍了在不强制用户登录/允许的情况下嵌入公共 Facebook 页面的活动源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这和之前问过几次的问题很相似,但无论我读什么,我仍然很困惑.

This is similar to questions asked several times before, but no matter what I read, I'm still confused.

我有一个公共 Facebook 页面,例如 White Collar,我需要将其活动源嵌入到我的 Android 应用程序中.我了解如何获取 app-id 和 app-secret,但我不明白如何获取短期访问令牌,我知道这是获得长期访问令牌所必需的.

I have a public Facebook page, like White Collar for example, whose activity feed I need to embed into my Android app. I understand how to get the app-id and app-secret, but I don't understand how to get the short-lived access token, which I understand is necessary to get a long-lived access token.

据我所知,这很可能是错误的,用户必须通过应用登录才能获得短期访问令牌,但我不希望任何用户必须登录才能查看活动提要.

From what I understand, which can quite possibly be wrong, the user has to login through the app to get a short-lived access token, but I don't want any user to have to login to view the activity feed.

一旦我有了它,我该如何使用它将此活动提要引入我的应用程序?

Once I have that, how do I then use it to bring this activity feed into my app?

这方面的 Facebook 文档很糟糕,所以我需要一些帮助.

The Facebook documentation for this is terrible so I need some help.

如果它或其他任何需要特定于站点的权限,我可以访问相关站点.

If it or anything else requires site-specific permissions, I have access to the site in question.

谢谢!

推荐答案

要获取公共 Facebook 页面(如 White Collar)的活动源,请按以下步骤操作:

To get the activity feed of a public Facebook page, like White Collar, follow these steps:

1) 通过选择现有应用程序或在此网址创建新应用程序来获取您的应用程序 ID 和应用程序机密:

1) Get your App-id and App-secret by choosing an existing app or creating a new one at this url:

https://developers.facebook.com/apps/

2) 通过向这个 url 发出 GET 请求来获取访问令牌:

2) Get an access token by making a GET request to this url:

https://graph.facebook.com/oauth/access_token?client_id=" + APP_ID + "&client_secret=" + APP_SECRET + "&grant_type=client_credentials

3) 获取您的粉丝专页的 page-id.为此,您需要页面名称.转到您在 facebook 上的粉丝页面并查看网址.它将具有以下形式:

3) Get the page-id of your fan page. To do this, you need the page-name. Go to your fan page on facebook and look at the url. It will have this form:

https://www.facebook.com/{fan-page-name}

一旦你有了它,就向这个网址发出 GET 请求:

Once you have that, make a GET request to this url:

https://graph.facebook.com/{fan-page-name}?access_token={access-token}

它会返回一堆 JSON.您正在寻找第一个id"元素.这是您的页面 ID.

It will return a bunch of JSON. You're looking for the first "id" element. This is your page-id.

4) 通过对这个 url 的 GET 请求获取粉丝页面 JSON 数据:

4) Get the fan page JSON data with a GET request to this url:

https://graph.facebook.com/" + page-id + "/feed?access_token=" + URLEncoder.encodeUTF8(access-token)

为了避免抛出异常,我不得不使用 URLEncoder.encodeUTF8().您要查找的数据位于数据"元素下.

To avoid having exceptions thrown, I had to use URLEncoder.encodeUTF8(). The data you're looking for is under the "data" element.

我找不到任何可以为我对 Facebook 提要进行 JSON 解析的内容,但我确实找到了这个 教程 它将为您做很多格式设置,使其看起来像 Facebook.

I wasn't able to find anything that would do the JSON parsing of the Facebook feed for me, but I did find this tutorial that will do a lot of the formatting for you to make it look like Facebook.

希望能帮助其他尝试这样做的人.

Hope that helps anyone else trying to do this.

这篇关于在不强制用户登录/允许的情况下嵌入公共 Facebook 页面的活动源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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