获取Access_token来读取Page Insights

发布于 2024-12-04 22:30:47 字数 1522 浏览 1 评论 0原文

我一直致力于使用 python 来访问 Facebook 见解信息。除了我开发的应用程序的应用程序见解之外,我还能够获取公共信息(例如,来自可口可乐页面的“喜欢”)。

因为我是页面和应用程序的管理员和开发人员,所以当我访问 facebook.com/insights 时,我会看到页面部分和应用程序部分。我希望能够从图形 API 中获取对这两者的见解,并将它们存储在我的个人数据库中。获得应用程序洞察并不困难。我在创建应用程序时获得了 app_id 和 app_secret,然后按照此页面 http: //developers.facebook.com/docs/authentication/。这给了我一个应用程序 access_token,我可以用它来获取应用程序见解。

当尝试对页面执行相同操作时,我遇到了更多麻烦。正如许多之前的帖子所提到的,大多数 Facebook 文档都与 Facebook 应用程序获取 access_token 来管理或读取页面中的见解有关。据我所知,这对于与用户页面交互的应用程序很有用。然而,我的直觉告诉我,我应该能够通过 read_insights 获取我作为管理员的页面的访问令牌,而无需通过外部应用程序。

我能够阅读页面见解的唯一方法是使用 Graph Api Explorer。我使用Explorer获取了access_token(通过access_token按钮,允许Explorer访问我的个人数据并请求manage_pages和read_insight扩展权限)。然后,我按照上面发布的 /docs/authentication/ 页面的页面登录下的说明操作,获取我管理的 Facebook 页面的 access_token。然后我终于可以运行 https://graph.facebook.com/PAGE_ID/insights?access_token= RETRIEVED_TOKEN。然而,这是一种查找 access_token 的极其麻烦的方法。有没有一种方法可以不那么麻烦地获得这个令牌?感谢您的帮助。我已经为此苦苦挣扎有一段时间了。

我还包含了用于获取应用程序访问令牌的代码。

def get_access_token():
    args = dict(client_id=FACEBOOK_APP_ID, client_secret=FACEBOOK_APP_SECRET, grant_type="client_credentials" )
    url = "https://graph.facebook.com/oauth/access_token?" + urllib.urlencode(args)
    response = urlparse.parse_qs(urllib.urlopen(url).read())
    access_token = response['access_token'][0]
    return access_token

I've been working on using python to get access to Facebook insights information. I was able to get public information (e.g. 'likes' from cocacola's page) in addition to app insights for apps that I have developed.

Because I am the admin and developer for both pages and apps, when I go to facebook.com/insights I will see a section for pages and a section for apps. I want to be able to get insights for both from the graph api and store them on my personal database. Getting the app insights were not difficult. I obtained my app_id and app_secret when I created my app and then followed the process under App Login at this page http://developers.facebook.com/docs/authentication/. This gave me an app access_token which I could use to get app insights.

When attempting to do the same for pages, I have had more trouble. As many previous posts have mentioned, most of the facebook documentation has to do with a facebook app getting an access_token to manage or read insights from a page. I understand that this is useful for apps that interact with a user's page. However, my instinct says that I should be able to get an access token with read_insights for a page that I am the administrator of without having to go through an external app.

The only way that I've been able to read the insights for my page has been using the Graph Api Explorer. I used the Explorer to obtain an access_token (through the access_token button, allowing the Explorer to access my personal data and requested manage_pages and read_insight extended permision). Then I followed the instructions under Page Login at the /docs/authentication/ page that I posted above, to get an access_token for the facebook page I administer. Then I could finally run https://graph.facebook.com/PAGE_ID/insights?access_token=RETRIEVED_TOKEN. However, this is an incredibly cumbersome way of finding the access_token. Is there a way to get this token that is less cumbersome? Thanks for your help. I've been struggling with this for quite a while.

I've also included the code that I used to get the access token for my app.

def get_access_token():
    args = dict(client_id=FACEBOOK_APP_ID, client_secret=FACEBOOK_APP_SECRET, grant_type="client_credentials" )
    url = "https://graph.facebook.com/oauth/access_token?" + urllib.urlencode(args)
    response = urlparse.parse_qs(urllib.urlopen(url).read())
    access_token = response['access_token'][0]
    return access_token

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

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

发布评论

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

评论(1

小耗子 2024-12-11 22:30:47

为什么不使用经典方式:

  • 创建一个应用程序并使用 facebook(例如 JS SDK)登录它,并具有 offline_accessread_insights 权限。
    Offline_access 将为您提供一个永久的 access_token,您可以随时使用它来访问见解。
  • JS SDK(方法FB.login)将返回一个对象,其中包含您需要的access_token。

Why not using classic way:

  • Create an app and login to it using facebook (JS SDK for example), with the offline_access and read_insights permission.
    The offline_access will give you a permanent access_token that you can use to access the insights anytime you want.
  • The JS SDK (method FB.login) will return an object, containing the access_token you need.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文