简体   繁体   English

Facebook获得访问令牌

[英]Facebook get access Token

How to get a "access token" using Facebook Graph API. 如何使用Facebook Graph API获取“访问令牌” I have app ID, the username and password of the user. 我有应用ID,用户的用户名和密码。 Just i need to get the access token so that i may be able to access news feed,.... and others. 只是我需要获取访问令牌,以便我可以访问新闻源,....和其他人。

Okay so you need to get the access_token of a user in JavaScript. 好的,所以你需要在JavaScript中获取用户的access_token Here you go: 干得好:

  1. Start reading the JavaScript SDK documentation 开始阅读JavaScript SDK文档
  2. 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> 
  3. As mentioned in the documentation : 文档中所述:

    Calling FB.login results in the JS SDK attempting to open a popup window. 调用FB.login会导致JS SDK尝试打开弹出窗口。 As such, this method should only be called after a user click event, otherwise the popup window will be blocked by most browsers. 因此,只应在用户单击事件后调用此方法,否则大多数浏览器都会阻止弹出窗口。

  4. 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! 如果确实如此,直接向Facebook报告!

  5. It's "JavaScript" not "Java Script" :-) 这是“JavaScript”而非“Java Script”:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM