简体   繁体   中英

How do I convert from an app token to a page token using the Facebook graph API?

I'm using the Facebook .NET SDK.

I can generate an app access like so:

var client = new FacebookClient();
dynamic appAccessToken =
            client.Get(
                string.Format("/oauth/access_token?client_id={0}&client_secret={1}&grant_type=client_credentials", appId, appSecret));

which brings me back an access token in the format {appId}|{token}

If I then pass this back into the client object I hoped to get a page access token, but I'm just getting back the page Id, where I as expecting to get the page Id and an access token.

Full code:

var client = new FacebookClient();
dynamic appAccessToken =
            client.Get(
                string.Format("/oauth/access_token?client_id={0}&client_secret={1}&grant_type=client_credentials", appId, appSecret));
client.AccessToken = appAccessToken.access_token;
dynamic tokens = client.Get(string.Format("/v2.5/{0}?fields=access_token", pageId));

To get a Page Token, you need to authorized with the manage_pages permission and use the /me/accounts endpoint to get Page Tokens for all your Pages. Or /page-id?fields=access_token for a single Page. You MUST use a User Token with manage_pages though, you can´t just use an App Token. App Tokens are not tied to a User (and the Pages he manages).

More information:

Make sure you understand the difference between App Token, User Token and Page Token. And of course you can´t get a Page Token for Pages you don´t manage, just in case it´s not clear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM