gpt4 book ai didi

Facebook 网站 API : Login and display user image and Name. 主动访问 token 错误

转载 作者:行者123 更新时间:2023-12-04 05:39:19 25 4
gpt4 key购买 nike

我的问题是显示一个登录按钮和(一旦用户登录)显示他的个人资料图片、姓名和“注销”链接。

在 facebook api 文档(这里 http://developers.facebook.com/docs/guides/web/#login )中,我找到了这个例子:

 <html>
<head>
<title>My Facebook Login Page</title>
</head>
<body>

<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID
channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.api('/me', function(user) {
if (user) {
var image = document.getElementById('image');
image.src = 'http://graph.facebook.com/' + user.id + '/picture';
var name = document.getElementById('name');
name.innerHTML = user.name
}
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>

<div align="center">
<img id="image"/>
<div id="name"></div>
</div>

</body>
</html>

那应该做我正在寻找的。我用我的 app_id 和我的域站点 (http://localhost/index.html) 替换了 'MY_APP_ID' 和 MY_DOMAIN.COM。我还添加了一个登录按钮,正如我在文档中找到的那样(该按钮有效并允许我登录),但没有显示图像或名称。我在控制台中编写了“用户”对象,它包含以下内容:
error: Object
code: 2500
message: "An active access token must be used to query information about the current user."
type: "OAuthException"

我应该如何使用这个“主动访问 token ”?

最佳答案

为了完成任何用户数据检索,每个 Facebook 应用程序都必须首先对用户 session 进行身份验证,以确保该应用程序具有最终用户检索其数据的权限。

引用 :https://developers.facebook.com/docs/authentication

使用 Javascript SDK 检索他们的访问 token ,您应该能够开始检索他们的用户显示名称和图像。

Facebook JS SDK :https://github.com/facebook/facebook-js-sdk/

关于Facebook 网站 API : Login and display user image and Name. 主动访问 token 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11472908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com