2012-05-07 72 views
0

我正在使用此代码,但它返回空数据数组。我的access_token具有所有权限。
我知道PAGE_ID,现在我需要从此页面获取活动。
感谢如何从Facebook获取页面事件?

<div id="fb-root"></div> 
    <script> 
     window.fbAsyncInit = function() { 
     FB.init({ 
      appId  : APP_ID, // App ID 
      status  : true, // check login status 
      cookie  : true, // enable cookies to allow the server to access the session 
      xfbml  : true // parse XFBML 
     }); 
     // Additional initialization code here 
     }; 

     // 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)); 

     var interval = setInterval(function() { 
      if (typeof FB != 'undefined') { 
       clearInterval(interval); 
       FB.api('/' + PAGE_ID +'/events?access_token=' + ACCESS_TOKEN, function(response) { 
        //do something with response 
       }); 
      } 
     }, 20); 
    </script> 

回答

1

我的第一个针对的access_token我的应用程序,我从http://developers.facebook.com/tools/explorer/得到是错误的。 (也许它只适用于测试模式)因为我无法通过此access_token获取事件。
http://developers.facebook.com/docs/authentication/applications/写着:

应用程序的访问令牌一般不会过期。一旦生成,它们将无限期地有效。
为了获得一个App访问令牌,执行HTTP GET上: https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&grant_type=client_credentials

我得到了使用HTTP GET ACCESS_TOKEN,本我的access_token得到Facebook的页面事件:https://graph.facebook.com/PAGE_ID/events

+0

有没有人知道它为什么不能在这个页面上工作? https://www.facebook.com/pages/La-CALLE-Jam-Sessions/404870736262643?id=404870736262643&sk=events – surfealokesea

1

这不是从你的代码清楚你是如何获得的access_token - 您使用的是在您需要检索事件的页面\帐户的访问令牌?我一直在做这件事的方式(不知道我在哪里采用这种技术)页面事件是循环访问用户帐户,以获取有关页面的访问令牌。像这样的(PHP)的东西

$accounts = $facebook->api('/me/accounts'); 
foreach($accounts['data'] as $account){ 
    if($account['id'] == $page_id){ 
     $page_access_token = $account['access_token']; 
    } 
} 
+0

我有点误解。也许我错了。我需要从这个页面获取活动:facebook.com/ExamplePage。这不是我的页面,但此页面中的事件是公开的。然后我创建了新的ExampleApp,通过Graph API Explorer获取访问令牌。我不知道如何关联我的ExampleApp和ExamplePage。看起来ExampleApp采用的access_token对于ExamplePage无效。 – Ikrom

+1

我的代码可能是矫枉过正只是阅读活动 - 事实证明,我是使用page_access_token一些其他事件管理在后面的过程。根据[页面文档](https://developers.facebook.com/docs/reference/api/page/),任何有效的access_token都足以获得事件连接。 –