1

好吧,我们可以做一个自动更新用户状态的网站,对吧?但是我遇到了一个问题。我们的目标用户是中国人,也就是说母语也是中文,我想用中文更新用户的状态。但是,mojibake 出现在状态中,而英文可以正确显示。这是我的代码:

<?php
session_start();
//facebook application
$fbconfig['appid' ]     = "APP_ID";
$fbconfig['secret']     = "APP_SECRET";
$fbconfig['baseurl']    = "URL";    
$user            =   null; //facebook user uid
try{
    include_once "facebook.php";
}
catch(Exception $o){
    error_log($o);
}
// Create our Application instance.
$facebook = new Facebook(array(
  'appId'  => $fbconfig['appid'],
  'secret' => $fbconfig['secret'],
  'cookie' => true,
));

//Facebook Authentication part
$user       = $facebook->getUser();

$loginUrl   = $facebook->getLoginUrl(
        array(
            'scope'         => 'email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown',
            'redirect_uri'  => $fbconfig['baseurl']
        )
);

$logoutUrl  = $facebook->getLogoutUrl();


if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    //you should use error_log($e); instead of printing the info on browser
    d($e);  // d is a debug function defined at the end of this file
    $user = null;
  }
}


//if user is logged in and session is valid.
if ($user){
    //get user basic description
    $userInfo           = $facebook->api("/$user");



    //update user's status using graph api
    //http://developers.facebook.com/docs/reference/dialogs/feed/
    if (isset($_GET['publish'])){
        try {
            $publishStream = $facebook->api("/$user/feed", 'post', array(
                'message' => "MESSAGE", 
                'link'    => 'LINK',
                'picture' => 'PIC_LINK',
                'name'    => 'WEB NAME',
                'description'=> 'DESCRIPTION'
                )
            );
            //as $_GET['publish'] is set so remove it by redirecting user to the base url 
        } catch (FacebookApiException $e) {
            d($e);
        }
        $redirectUrl     = "URL";
        header("Location: $redirectUrl");
    }

    //update user's status using graph api
    //http://developers.facebook.com/docs/reference/dialogs/feed/
    if (isset($_POST['tt'])){
        try {
            $statusUpdate = $facebook->api("/$user/feed", 'post', array('message'=> $_POST['tt']));
        } catch (FacebookApiException $e) {
            d($e);
        }
    }
}

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

我想在设置 $_GET['publish']=1 时更新用户的状态。任何帮助将不胜感激。

4

0 回答 0