douti9253 2012-08-13 07:31
浏览 65

更新Facebook状态时Mojibake(中文字符显示不正确)

Well, we can make a website that automatically update users' status, right? But I have come across a problem. Our target users are Chinese, which means the mother language is Chinese also, and I would like to update the users' status in Chinese. However, mojibake appears in the status while English can be displayed correctly. Here is my code:

<?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>';
}
?>

I want to update the users' status when setting $_GET['publish']=1. Any help will be appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
    • ¥20 关于URL获取的参数,无法执行二选一查询
    • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
    • ¥15 marlin编译错误,如何解决?
    • ¥15 有偿四位数,节约算法和扫描算法
    • ¥15 VUE项目怎么运行,系统打不开
    • ¥50 pointpillars等目标检测算法怎么融合注意力机制
    • ¥20 Vs code Mac系统 PHP Debug调试环境配置
    • ¥60 大一项目课,微信小程序
    • ¥15 求视频摘要youtube和ovp数据集