如何从新的“添加到时间线身份验证”对话框中获取 ACCESS_TOKEN
我目前有以下情况。在我的网站上,用户可以访问他的设置页面。此页面有一个名为“Facebook”的选项卡。在此页面上,我有以下代码,可让用户允许我的网站在完成特定操作时发布到他的时间线:
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#appId={APP_ID_HERE}&xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-add-to-timeline" data-show-faces="false" data-mode="button"></div>
当用户单击按钮时,它将转发到“添加到时间线”对话框。当用户单击“允许”时,用户将被重定向回我网站上的设置页面。
问题是;我如何从中获取访问令牌?根据教程中的这一行,我需要一个用户访问令牌来发布到他的时间线:
https://graph.facebook.com/me/YOUR_NAMESPACE:cook?recipe=OBJECT_URL&access_token=ACCESS_TOKEN
I currently have the following situation. On my website, the user can access his settings page. This page features a tab called 'Facebook'. On this page, I have the following code that lets the user allow my website to post to his timeline when completing a certain action:
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#appId={APP_ID_HERE}&xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-add-to-timeline" data-show-faces="false" data-mode="button"></div>
When the user clicks the button, it is forwarded to the Add to Timeline dialog. When the user clicks Allow, the user gets redirected back to his settings page on my website.
The question is; how do I get an access token out of this? I need a user access token to post to his timeline, according to this line from the tutorial:
https://graph.facebook.com/me/YOUR_NAMESPACE:cook?recipe=OBJECT_URL&access_token=ACCESS_TOKEN
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需告诉用户登录
,然后在您想要的任何地方使用此代码
,其中 cooking 是一个对象
Just tell user to get log in
and after that, use this code everywhere you want
Where cooking is an object