Facebook获取访问令牌 [英] Facebook get access Token
问题描述
如何使用Facebook Graph API获取访问令牌。我有应用程序ID,用户的用户名和密码。只需要获取访问令牌,以便我可以访问新闻Feed .... ....等等。
How to get a "access token" using Facebook Graph API. I have app ID, the username and password of the user. Just i need to get the access token so that i may be able to access news feed,.... and others.
推荐答案
好的,所以你需要在JavaScript中获得用户的 access_token
。你去:
Okay so you need to get the access_token
of a user in JavaScript. Here you go:
- 开始阅读 JavaScript SDK文档
-
如下所示将让您开始:
- Start reading the JavaScript SDK documentation
Something like the below will get you started:
<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
});
// this shouldn't be called directly, but instead should be initiated with a user click event
FB.login(function(response) {
if (response.authResponse) {
console.log('Access Token: ' + response.authResponse.accessToken);
} else {
console.log('User cancelled login or did not fully authorize.');
}
});
};
// 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>
如文档:
调用FB.login导致JS SDK尝试打开一个弹出式
窗口。因此,此方法只能在用户单击
事件后调用,否则弹出窗口将被大多数浏览器阻止。
Calling FB.login results in the JS SDK attempting to open a popup window. As such, this method should only be called after a user click event, otherwise the popup window will be blocked by most browsers.
永远 请求用户密码,也可以请求任何您!如果是,请直接向Facebook报告!
NEVER EVER ask for the user password nor give it to ANY application if it asks you! and if it does, report it to Facebook directly!
这是JavaScript而不是Java Script: - )
It's "JavaScript" not "Java Script" :-)
这篇关于Facebook获取访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!