在没有用户身份验证的情况下发布 Facebook 页面的链接
基本上我有一个网络应用程序,它将发布到 Facebook 页面(不是个人资料)墙的链接。
据我所知,我需要一个永久令牌才能执行此操作。 Twitter 直接给了我一个帐户,所以我希望 Facebook 也能有类似的东西。但是,我通过 manage_pages
权限获得的令牌已过期。
从身份验证文档来看,这就是我一直在做的事情:
请求令牌来管理页面:
https://www.facebook.com/dialog/oauth?client_id=123456789123&redirect_uri=http://myapp.com/fb&scope=manage_pages&response_type=token
获取令牌返回我打算将其粘贴到我的应用程序配置中的网址:
http://myapp.com/fb#access_token=123123123123123%7C2.18VYbalblablablaswhg__.3 600.1304294400.1-615173155%7CTzb_U9ma0LIPJXNzqsZ_xUJpfn8&expires_in=4205
当我实际尝试用此方法发布到页面时,我收到过期错误。
$post_params = array(
'access_token' => self::$page_token,
'message' => $string
);
$response = $fb_app->api('/'.self::$page_id.'/feed','POST', $post_params);
Basically I have a web app that will be posting links to a facebook page(not profile) wall.
As far as I know I need a permanent token to do this. Twitter gives me one straight off the account, so I was hoping facebook would have something similar. However the token I get with the manage_pages
permission has an expiry.
From the authentication docs this is what I've been doing:
request token to manage pages:
https://www.facebook.com/dialog/oauth?client_id=123456789123&redirect_uri=http://myapp.com/fb&scope=manage_pages&response_type=token
get token back the url which I intend paste it into my apps config:
http://myapp.com/fb#access_token=123123123123123%7C2.18VYbalblablablaswhg__.3600.1304294400.1-615173155%7CTzb_U9ma0LIPJXNzqsZ_xUJpfn8&expires_in=4205
When I actually try to post to the page with this, I get an expired error.
$post_params = array(
'access_token' => self::$page_token,
'message' => $string
);
$response = $fb_app->api('/'.self::$page_id.'/feed','POST', $post_params);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要offline_access 权限才能获取永久令牌。
如果您打算作为页面本身发布,则需要从该页面的 /USER_ID/accounts 获取令牌,否则您将从您的个人资料中发布。如果你不打算作为页面发布,实际上不需要manage_pages权限,用户的publish_stream就足够了。祝你好运。
You need the offline_access permission to get a permanent token.
If you intend to post as the page itself, you need to get the token from /USER_ID/accounts for that page, else you will post from your profile. If you don't intend to post as the page, you actually don't need the manage_pages permission, publish_stream for the user is enough. Good luck.