如何通过代码获取页面访问令牌? [英] How to get Page Access Token by code?
问题描述
我需要为网页生成一个页面访问令牌,该网页将被使用该页面发布到其Facebook页面Feed。
是我做的:
- 转到图表API资源管理器
- 从下拉列表中选择我的应用程序
- 点击
获取访问令牌
- 选择正确的权限(
manage_pages
/user_events
)
要获取页面访问令牌
我必须运行我/ accounts
在Graph API资源管理器中。这将显示所有的页面,我有一个新的页面访问令牌(短命(约60分钟))到每一个。
这个页面
问题 p>
当另一个用户使用我的网页发布帖子时,我需要生成一个新的页面访问令牌
(在代码中)和然后使用它将用户页面发布到该网站的Facebook订阅源。问题是,我可以明确地不在那里给出这个帖子,我该如何处理?
我显然不能运行帐户
(代码)命令从这里获取页面访问令牌
。
我查看了扩展访问令牌,但是这将持续60天,那么这将是与上述相同的问题。
您需要的是扩展页面令牌:
- 使用
manage_pages
和publish_actions
生成用户访问令牌 - 生成扩展用户令牌(有效期为60天): https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id= [app-id]& client_secret = [app -secret]& fb_exchange_token = [short-lived-token]
- 调用
/ me / accounts
用户令牌获取扩展页面令牌
扩展页面令牌永久有效,因此您不需要生成一个新的时间。
来源(包括有关所有令牌的信息): http://www.devils-heaven.com/facebook-access-tokens/
I need to generate a Page Access Token for a webpage that I have, this token will be used by the webpage to post to its Facebook Page feed.
This is what I do :
- Go to Graph API Explorer
- Choose my app from the dropdown
- Click
Get Access Token
- Choose correct permissions(
manage_pages
/user_events
)
To get the Page Access Token
I have to run me/accounts
in the Graph API Explorer. This will show all the pages I got with a new Page Access Token (short lived(about 60 min)) to each one.
This Page Access Token
will work just fine to use in my C# code to post to the feed.
Problem
When another user uses my webpage to post a post I need to generate a new Page Access Token
(in code) and then use it to post the userpost to the site´s facebook feed. The problem is that I could clearly not be there to grant the post so how do I handle this?
I could obviously not run the me/accounts
(in code) command to get the Page Access Token
from here.
I have looked at extended Access Token but this will last 60 days and then it will be the same problem as above.
What you need is an Extended Page Token:
- generate User Access Token with
manage_pages
andpublish_actions
- generate Extended User Token (valid for 60 days): https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id=[app-id]&client_secret=[app-secret]&fb_exchange_token=[short-lived-token]
- call
/me/accounts
with the Extended User Token to get Extended Page Tokens
Extended Page Tokens are valid forever, so you don´t need to generate a new one all the time.
Source (including information about all the Tokens): http://www.devils-heaven.com/facebook-access-tokens/
这篇关于如何通过代码获取页面访问令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!