如何使Redirect_uri重定向到Facebook中的应用程序 - PHP / SDK

时间:2011-09-13 10:12:47

标签: php facebook authentication sdk

我制作了这个应用:http://apps.facebook.com/citynumbersfriends。用户授予权限后,会将其重定向到FB外部的应用程序。如何在画布视图中重定向到应用程序?

我已经尝试过将其设置REDIRECT_URI =的 'http://apps.facebook.com/citynumbersfriends/',但我在URL的此liek的无限循环结束:w1k5twJ0igxm7bAf30HfeAixibuF4xdHt1a94wSJ8M1BkRBHK8zHqWowqcD-G8-Dtcvrtw1sAx0qgLzKqQI5fm-1CYMHMiko80EPpsrvourUn2fPRE5UGNEcoSw38SXBd5ij9Ngt4yQwI#= _“&GT ; HTTP://apps.facebook.com/citynumbersfriends/状态= 6e21ca70b7aef6316b2b600a03d790bf&安培;代码= AQCFfLzwUWi1mDJ8r2eWLkjJ9vRUVyAPfMKJFVC13edSSeeoVIgfGExpvbCREki53hYQES5iE- w1k5twJ0igxm7bAf30HfeAixibuF4xdHt1a94wSJ8M1BkRBHK8zHqWowqcD-G8-Dtcvrtw1sAx0qgLzKqQI5fm-1CYMHMiko80EPpsrvourUn2fPRE5UGNEcoSw38SXBd5ij9Ngt4yQwI# = _

与不同的国家和地区代码值。

谁能告诉我我做错了什么?

我使用这部分代码:

    $loginUrl = $facebook->getLoginUrl(
            array(
            'app_id'  => $app_id,
            'req_perms' => 'publish_stream,status_update'
//          'redirect_uri' => $my_url
            )
    );

//--------------

         catch (FacebookApiException $e) {
            echo "<script type='text/javascript'>top.location.href = '$loginUrl';                 </script>";
            exit;
        }

完整的代码如下:

<?php
$name_search = $_GET['name_search'];
$invite = $_GET['invite'];
$reden = $_GET['reden'];
$foto = $_GET['foto'];


$app_id  = '195571338990';
$app_secret  = 'xxxxxxxxxxxxxx';
$my_url = 'http://apps.facebook.com/citynumbersfriends/';
$canvasPage = 'http://www.facebook.com/citynumbers';

$uid            =   null; //facebook user id
include ("facebook.php");

// Create our Application instance.
$facebook = new Facebook(array(
        'appId'  => $app_id,
        'secret' => $app_secret,
        'cookie' => true,
        ));

//Facebook Authentication part
//    $session = $facebook->getSession();
    $loginUrl = $facebook->getLoginUrl(
            array(
            'app_id'  => $app_id,
            'req_perms' => 'publish_stream,status_update'
            //'redirect_uri' => $my_url
            )
    );

    $me = null;

    if (1==2) {
        echo "<script type='text/javascript'>self.location.href = '$loginUrl';</script>";
        exit;
    }
    else {
        try {
                $uid      =   $facebook->getUser();
                $me     =   $facebook->api('/me');

$fql = "SELECT uid, name, first_name, pic_small FROM user WHERE strpos(lower(name),'$name_search') >= 0 AND uid IN (SELECT uid2 FROM friend WHERE uid1=".$uid.") order by name";

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<head>
    <link rel="stylesheet" href="http://citynumbers.com/styles/layout.css">
</head>

<table align='center' cellpadding='0' cellspacing='0' width='500px'>
<tr>
    <td colspan='4'><a target='new' href='http://facebook.com/citynumbers'><img alt='Ga naar de Citynumbers Fanpage' title='Ga naar de Citynumbers Fanpage' src='/images/layout/logo.jpg'></a></td>

</tr>
<tr><td colspan='4'>
<iframe src="//www.facebook.com/plugins/like.php?app_id=263168060373514&amp;href=http%3A%2F%2Fwww.facebook.com%2Fcitynumbers&amp;send=false&amp;layout=standard&amp;width=350&amp;show_faces=false&amp;action=like&amp;colorscheme=dark&amp;font&amp;height=40" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:350px; height:40px;" allowTransparency="true"></iframe>
</td></tr>


<tr><td colspan='4'>

<form id="form">
<h3>Nodig je vrienden uit om weer eens te gaan stappen!</h3>
<h3>Stap 1: Kies de reden waarom je wil stappen met je FB vriend</h3>
We moeten snel weer een keer uitgaan omdat:<BR>
<input type="radio" name="reden" <?if($reden=='ik me van de vorige keer weinig meer kan herinneren!'){echo "checked";} ?> value="ik me van de vorige keer weinig meer kan herinneren!" checked/>... ik me van de vorige keer weinig meer kan herinneren...<BR>
<input type="radio" name="reden" <?if($reden=='ik zin heb om weer met je te dansen!'){echo "checked";} ?> value="ik zin heb om weer met je te dansen!"/>...ik zin heb om weer met je te dansen!<BR>
<input type="radio" name="reden" <?if($reden=='we nodig moeten bijpraten!'){echo "checked";} ?> value="we nodig moeten bijpraten!"/>...we nodig moeten bijpraten!<BR>
<input type="radio" name="reden" <?if($reden=='het gewoon veel te lang geleden is!'){echo "checked";} ?> value="het gewoon veel te lang geleden is!"/>...het gewoon veel te lang geleden is!<BR>
<BR><BR>
<h3>Stap 2: Kies een foto</h3>
</td></tr>
<tr align='center'>
<td align='center'><img src='pics/facebook/girls_drinking_cocktails_tn.jpg' border='0'></td>
<td align='center'><img align='center' src='pics/facebook/girls-drinking-beer-271x300_tn.jpg' border='0'></td>
<td align='center'><img src='pics/facebook/drinking-students_tn.jpg' border='0'></td>
<td align='center'><img src='pics/facebook/clubbing_tn.jpg' border='0'></td>
</tr>
<tr>

<td align='center'><input type="radio" name="foto" <?if($foto=='http://citynumbers.com/pics/facebook/girls_drinking_cocktails_tn.jpg'){echo "checked";} ?> value="http://citynumbers.com/pics/facebook/girls_drinking_cocktails_tn.jpg" checked/></td>

<td align='left'><input type="radio" name="foto" <?if($foto=='http://citynumbers.com/pics/facebook/pics/facebook/girls-drinking-beer-271x300_tn.jpg'){echo "checked";} ?> value="http://citynumbers.com/pics/facebook/girls-drinking-beer-271x300_tn.jpg"/></td>

<td align='center'><input type="radio" name="foto" <?if($foto=='http://citynumbers.com/pics/facebook/drinking-students_tn.jpg'){echo "checked";} ?> value="http://citynumbers.com/pics/facebook/drinking-students_tn.jpg"/></td>

<td align='center'><input type="radio" name="foto" <?if($foto=='http://citynumbers.com/pics/facebook/clubbing_tn.jpg'){echo "checked";} ?> value="http://citynumbers.com/pics/facebook/clubbing_tn.jpg"/></td>
</tr>

<tr>
<td colspan='4'><BR><BR></td>
</tr>

<tr>
<td><img src='pics/facebook/Krakow-nightlife_tn.jpg' border='0'></td>
<td><img src='pics/facebook/Girls-having-Dinner-360x240_tn.jpg' border='0'></td>
<td><img src='pics/facebook/romantic-dinner-lg-84114188_tn.jpg' border='0'></td>
<td></td>
</tr>

<tr>
<td align='center'><input type="radio" name="foto" <?if($foto=='http://citynumbers.com/pics/facebook/Krakow-nightlife_tn.jpg'){echo "checked";} ?> value="http://citynumbers.com/pics/facebook/Krakow-nightlife_tn.jpg"/></td>

<td align='left'><input type="radio" name="foto" <?if($foto=='http://citynumbers.com/pics/facebook/pics/facebook/Girls-having-Dinner-360x240_tn.jpg'){echo "checked";} ?> value="http://citynumbers.com/pics/facebook/Girls-having-Dinner-360x240_tn.jpg"/></td>

<td align='center'><input type="radio" name="foto" <?if($foto=='http://citynumbers.com/pics/facebook/romantic-dinner-lg-84114188_tn.jpg'){echo "checked";} ?> value="http://citynumbers.com/pics/facebook/romantic-dinner-lg-84114188_tn.jpg"/></td>

<td align='center'></td>
</tr>


<tr><td colspan='4'>
<h3>Stap 3: Selecteer je vriend</h3><BR>

<?

echo "Type hier (een deel van) de naaam van je Facebook vriend:<BR><BR><input name='name_search' value='$name_search' type='text'><input name='url' value='$url' type='hidden'><INPUT TYPE=SUBMIT Name=SUBMIT Value='GO!'></Form><BR>";


if ($name_search<>''){


$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);

$fqlResult   =   $facebook->api($param);
if (is_array($param) && count($param)) {
echo "<table border=0><tr>";
$i=0;
foreach($fqlResult as $result)
{
$i=$i+1;

echo "<td valign=top width=80 height=100 border=1><a target='top' href='http://www.facebook.com/dialog/feed?app_id=195571338990&link=http://apps.facebook.com/citynumbersfriends&picture=".$foto."&name=Ik vind dat we snel weer eens moeten uitgaan omdat:&to=".$result['uid']."&caption=...".$reden."&description=Kijk%20snel%20welke%20redenen%20ik%20NIET%20gekozen%20heb...&message=Facebook%20Dialogs%20are%20so%20easy!&redirect_uri=http://apps.facebook.com/citynumbersfriends/?invite=sent'><img border=0 src=".$result['pic_small']."><BR>".$result['name']."</a></TD>";
if($i % 8 == 0){
echo "</tr><tr>";
}
}    


echo "<tr></td>";
echo "</form>";

if ($i==0){
    echo "Geen vrienden gevonden, probeer het opnieuw!";

}
else
    {
echo "<h3>Stap 4: klik op je vriend om hem of haar uit te nodigen!</h3>";
    }

if ($invite<>''){


    echo "<BR><BR>Nodig nog een andere vriend uit.";

}

echo "</td></tr></table>";
}

}   
;

        } catch (FacebookApiException $e) {
            echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
            exit;
        }
    }

    function d($d){
        echo '<pre>';
        print_r($d);
        echo '</pre>';
    }
?>

1 个答案:

答案 0 :(得分:2)

我使用此代码解决了问题:

$loginUrl='https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=195571338990&redirect_uri=http%3A%2F%2Fwww.facebook.com/citynumbers?sk=app_195571338990&scope=publish_stream,status_update';

案件结案!