2011-08-27 64 views
1

我需要在我的粉絲頁面上創建活動。但目前這些事件顯示在我的應用程序頁面上,而不是在我的粉絲頁面上。使用PHP在Fanpage上創建活動

你能告訴我一些關於如何做到這一點的信息嗎?

+3

您應該提供更多關於您用於創建事件的方法的信息 –

+0

而通過信息我們的意思是代碼... – ifaour

回答

0

您需要請求manage_pages權限,這將允許您訪問「頁面」令牌。您可以使用您的應用程序令牌和打算拿到令牌

https://graph.facebook.com/userId/accounts?access_token={appToken} 

然後,您除了可以用它來在所有者字段通過與頁面ID與事件數據的其餘部分。

這應該爲頁面創建事件。

0

看到此鏈接http://pastebin.com/WSHCDLdr

這可能會幫助你.........

PHP代碼在此鏈接在下面給出........

<?php 

require_once 'fb.php'; 

$pageId = "XXXXXXXXXXXXXXXXXXX"; 


define('API_SECRET', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); 

$baseurl = "http://example.com"; 

$facebook = new Facebook(array(
    'appId' => 'XXXXXXXXXXXXXXXXXX', 
    'secret' => API_SECRET, 
    'cookie' => true, 
    'fileUpload' => true 
)); 

$session = $facebook->getSession(); 

$me = null; 

// Session based API call. 
if ($session) { 
    $uid = $facebook->getUser(); 
// $me = $facebook->api('/me'); 
    $me = $facebook->api("/$pageId"); 
} 

if ($me) { 
    $logoutMe = $facebook->getLogoutUrl(array('next' => $base_url)); 
} else { 
    $loginMe = $loginUrl = $facebook->getLoginUrl(array(
     'display' => 'popup', 
     'next'  => $baseurl /*. '?loginsucc=1'*/, 
//  'cancel_url'=> $baseurl . '?cancel=1', 
     'req_perms' => 'create_event' 
    )); 
} 

// if user click cancel in the popup window 
if ($me && empty($_GET['session']) && empty($_COOKIE['fbs_' . API_SECRET])) { 
    die("<script>window.close();</script>"); 
} elseif($me && !empty($_GET['session'])) { 
    //only if valid session found and loginsucc is set, 
    //after facebook redirects it will send a session parameter as a json value 
    //now decode them, make them array and sort based on keys 
    $sortArray = get_object_vars(json_decode($_GET['session'])); 
    ksort($sortArray); 
    $strCookie = ""; 
    $flag  = false; 
    foreach($sortArray as $key=>$item){ 
     if ($flag) $strCookie .= '&'; 
     $strCookie .= $key . '=' . $item; 
     $flag = true; 
    } 

    //now set the cookie so that next time user don't need to click login again 
    setCookie('fbs_' . API_SECRET, $strCookie); 

    die("<script>window.close();window.opener.location.reload();</script>"); 
} 

if ($me) { 
    var_dump($me); 
    //Path to photo (only tested with relative path to same directory) 
// $file = "end300.jpg"; 
    //The event information array (timestamps are "Facebook time"...) 
    $time = time() + rand(1, 100) * rand(24, 64) * 3600; 
    $event_info = array(
     "privacy_type" => "SECRET", 
//  "name" => "Event Title " . time(), 
     "name" => "Test Event Title " . time(), 
     "host" => "Me ", 
     "start_time" => $time, 
     "end_time" => $time + 120, 
     "location" => "London " . time(), 
     "description" => "Event Description " . time() 
    ); 
    //The key part - The path to the file with the CURL syntax 
// $event_info[basename($file)] = '@' . realpath($file); 
    //Make the call - returns the event ID 
// var_dump($facebook->api('me/events','post',$event_info)); 
    var_dump($facebook->api("$pageId/events", 'post', $event_info)); 
?> 
<a href="<?= $facebook->getLogoutUrl() ?>">Logout</a> 
<? 
} else { ?> 
<script type="text/javascript"> 
    var newwindow; 
    var intId; 
    function login(){ 
     var screenX = typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft, 
      screenY = typeof window.screenY != 'undefined' ? window.screenY : window.screenTop, 
      outerWidth = typeof window.outerWidth != 'undefined' ? window.outerWidth : document.body.clientWidth, 
      outerHeight = typeof window.outerHeight != 'undefined' ? window.outerHeight : (document.body.clientHeight - 22), 
      width = 500, 
      height = 270, 
      left  = parseInt(screenX + ((outerWidth - width)/2), 10), 
      top  = parseInt(screenY + ((outerHeight - height)/2.5), 10), 
      features = (
      'width=' + width + 
      ',height=' + height + 
      ',left=' + left + 
      ',top=' + top 
      ); 
     newwindow=window.open('<?=$loginUrl?>','Login by facebook',features); 
     if (window.focus) {newwindow.focus()} 
     return false; 
    } 
</script> 
Please login to Facebook and we will setup the event for you! <br /> 
<a href="#" onclick="login();return false;"> 
    <img src="http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif" border="0"> 
</a> 
<?php } ?> 
+0

提供答案時,您應該在實際答案中包含方法/示例。如果您的鏈接被刪除,您的答案將完全無用。 – Curt

+0

謝謝柯特,我在答案中添加了代碼....... –