Facebook invites partialy working..
- by dugi007
Hello!
im new to facebook api and i have a litle problem.. i created iframe app and im using the folowing code to invite my friends. invitation screen renders and im able to send invitation. when someone accepts invitation it redirects them to the following link:
http://www.facebook.com/reqs.php#!//apps.facebook.com/erste_app/
and nothing happens (only the facebook header apears and thats all)...when they manualy repost that link they are redirected to app and everything works...
<?php
include 'facebook.php';
define( 'FB_API_KEY', 'e23463********9c7ebfd6d34' );
define( 'FB_SECRET', '5f6************7efff5c8cb8' );
define( 'FB_APPID', '312*********23' );
define( 'FB_CANVAS_URL', 'http://apps.facebook.com/erste_app/' );
define( 'FB_APP_HOME_URL', 'http://www.bijelarukavica.com/test/' );
define( 'FB_APP_NAME', 'Zaigraj s Rokom' );
$bOK=SendStandardInvitation("", false);
function SendStandardInvitation($to, $bNewStyle = true) {
$typeword = FB_APP_NAME;
// Warning: double quotes in the content string will screw up the invite signature process
$content = '<fb:req-choice url=\' ' . FB_CANVAS_URL . '\' label=\'Check out ' . FB_APP_NAME . ' />';
// if your have post add routines take them to that add app URL instead.
$actionText = 'Probaj jesi bolji od mene uz "' . FB_APP_NAME . '".';
$bOK = SendNewRequest($to, $typeword, $content, $actionText);
return $bOK;
}
function SendNewRequest($to, $typeword, $content, $actionText, $bInvitation = true) {
$facebook = new Facebook(FB_API_KEY,FB_SECRET);
$to = implode(",", $facebook->api_client->friends_get('',''));
$bInviteAll = (!$to || $to == "" ? true : false); $excludeFriends = null;
if (!$bInviteAll)
$excludeFriends = $facebook->api_client->friends_get();
else
// Get all friends with the app
$excludeFriends = $facebook->api_client->friends_getAppUsers();
$excludeFriendsStr = null;
foreach ($excludeFriends as $userid) {
$pos = strpos($to, (string)$userid);
if ($pos !== false) continue;
if ($excludeFriendsStr) $excludeFriendsStr .= ','; $excludeFriendsStr .= $userid; }
$params = array(); $params['api_key'] = FB_API_KEY;
$params['content'] = $content;
// Don't use htmlentities() or urlencode() here
$params['type'] = $typeword;
$params['action'] = FB_CANVAS_URL ;
$params['actiontext'] = $actionText;
$params['invite'] = ($bInvitation ? 'true' : 'false');
$params['rows'] = '5';
$params['max'] = '20'; $params['exclude_ids'] = $excludeFriendsStr;
$params['sig'] = $facebook->generate_sig($params, FB_SECRET);
$qstring = null;
foreach ($params as $key => $value) {
if ($qstring) $qstring .= '&';
$qstring .= "$key=".urlencode($value); }
$inviteUrl = 'http://www.facebook.com/multi_friend_selector.php?';
$facebook->redirect($inviteUrl . $qstring);
return true;
}
$facebook->api_client->notifications_sendRequest
function SendRequest($to, $typeword, $content, $bInvitation = true) {
$facebook = new Facebook(FB_API_KEY,FB_SECRET);
$image = FB_APP_HOME_URL . 'logo.gif';
$result = $facebook->api_client->notifications_sendRequest($to, $typeword, $content, $image, $bInvitation);
$url = $result;
if (isset($url) && $url) { $facebook->redirect($url . '&canvas=1&next=index.php'); return true; } $bOK = ($result && $result != "");
return $bOK;
}
SendStandardInvitation($to, $bNewStyle = false)
?>