我有一个带有文本框和按钮的页面,我想发布到twitter文本框的内容。使用jmathai-twitter-async的库更新ajax调用中的twitter状态
我已经创建了一个dev.twitter应用程序,我先检查用户是否已经验证过了,然后我添加以下到按钮的单击事件:
//sending message
$.post('postStatus.php',{
status:message
},function(response){
$("#debug").html(response);
});
文件postStatus.php
是(初稿):
<?php
require_once 'EpiCurl.php';
require_once 'EpiOAuth.php';
require_once 'EpiTwitter.php';
require_once 'secret.php';
//is connected ?
/*
$twitterObj = new EpiTwitter($consumerKey, $consumerSecret);
$oauth_token = @$_GET['oauth_token'];
if($oauth_token == '')
die();
*/
//validate message
[email protected]$_POST['status'];
$message = trim($message);
if ($message === '')
die();
//send
$twitterObj->setToken($_COOKIE['oauth_token'],$_COOKIE['oauth_token_secret']);
$status=$twitterObj->post_statusesUpdate(array('status' => $message));
$status->response;
echo 'Your status has been updated';
我在验证$message
时丢失了什么吗?如果有的话,我应该在try/catch块中包含哪些内容?最后,我应该有postStatus.php
返回500错误,或者是die()
好吗?
$ consumerKey和$ consumerSecret在所需的secret.php中定义 – Manu 2012-03-01 10:04:07