[英]Facebook Graph API does not work
I spent a while trying to make a basic code working to be able to use the Facebook Graph API
.我花了一段时间尝试编写一个基本代码,以便能够使用Facebook Graph API
。 I think the issue is that the action is never launched when I click the button.我认为问题是当我单击按钮时该操作从未启动。 I tried to add an alert in document.getElementById('login').onclick = function() {
but it never goes through.我试图在document.getElementById('login').onclick = function() {
添加一个警报,但它从未通过。 Do you have any idea what could be the issue ?你知道可能是什么问题吗?
Thanks !!谢谢 !!
Here is the code ('000000000000000' is not my real app ID, I just replaced it for the post):这是代码('000000000000000' 不是我真正的应用程序 ID,我只是为帖子替换了它):
<html> <head> </head> <body> <script type="text/javascript"> window.fbAsyncInit = function() { var appID = '0000000000000000'; FB.init({ appId: appID, status: true, cookie: true, xfbml: true }); // This bit adds the login functionality to the login // button when api load is complete document.getElementById('login').onclick = function() { alert("test"); FB.login(function(response) { if (response.authResponse) { FB.api('/me', function(info) { login(response, info); }); } else { //user cancelled login or did not grant authorization showLoader(false); } }, {perms:'read_stream,publish_stream,offline_access'}); } }; (function() { var e = document.createElement("script"); e.async = true; e.src = "https://connect.facebook.net/en_US/all.js?xfbml=1"; document.getElementById("fb-root").appendChild(e); }()); </script> <button id="login" >My login button</button> </body> </html>
That would be the correct code:那将是正确的代码:
document.getElementById('login').addEventListener('click', function() {
console.log('test');
});
More information: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener更多信息: https : //developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.