Making Page Access Tokens Never Expire With 2016 F

2020-03-06 02:55发布

The application we are building is both an iOS and Android mobile app that pairs high school students with nonprofits to help manage their Facebook pages. We assign each student to one nonprofit, make them an administrator of their Facebook page, and allow them to create posts on behalf of the organization to reach new audiences. Each student is then given a score that comprises of the likes, comments, shares, etc. garnered by the student's posts on the page.

The trouble we are having is with the Facebook Graph API. We need someone familiar with the current Facebook SDK that can help us devise a better plan to retrieve specific data.

Currently, we have made a profile that is an admin for every nonprofit Facebook page on our platform. We use this admin access to retrieve a user access token and a page access token for each Facebook page. But with the new SDK, we can only make page access tokens last 60 days, making us constantly have to refresh the token to retrieve the data. However, when we refresh, Facebook asks us to authenticate with a username and password which slows down our backend with high a risk of our server crashing. Also, this method increases the amount of daily requests we make to Facebook for data, running the risk that Facebook might shut down our access completely as we add more users to the app.

So our problem really lies with this page access token because we are trying to query data from multiple different Facebook pages. The data we are requesting is also very specific because we only want the data from posts published from a specific "admin_creator" on the page (aka the student only, not any other admin) to assign the student a score.

Is there a way to make page access tokens never expire with the current Facebook SDK? There are posts that describe this process, but they were for 2014, not the current version. Also, is there a better way than our current method to retrieve the specific data we need?

1条回答
叛逆
2楼-- · 2020-03-06 03:36

Steps:

  1. Get the user-access-token having the permission manage_pages with it.
  2. Extend the token using (do it server side, since it involves app secret)

    https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id={your_app_id}&client_secret={your_app_secret}&fb_exchange_token={user_token_from_last_step}

  3. Use the extended token from above step and use the API-

    /v2.5/{page-id}?fields=access_token
    

    You'll get the page access token in response, that'll never expire.

I think you're at step 2, just follow the step 3 and you're good to go.

I'll recommend you go through this page about the access tokens and things will be much clearer.

查看更多
登录 后发表回答