我最終使用curl的codeigniter幫助函數發佈到Facebook。以下是代碼。
function facebook($data) {
$CI =& get_instance();
$CI->load->model('fk_model');
$token = $CI->fk_model->fk_cookie();
$attachment = array(
'access_token' => $token['access_token'],
'message' => $data['text'],
'link' => $data['link'],
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/' . $token['id'] . '/feed');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
curl_close($ch);
}
多數民衆贊成在偉大的。你可以發佈模型或至少如何獲取令牌? – Rooster 2011-12-26 15:37:12