Please trying to work using TwitterAPIExchange. help me out
This code doesn’t work. It’s supposed to get the post and it’s url and send to twitter. it doesn’t show any error. the problem is from the “build_twitter_status” cause that’s what’s going to be pages to $postfields.
//This registers the events and gets the post and sends it to twitter
public function process_event($event, $userid, $handle, $cookieid, $params) {
require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
require_once QA_INCLUDE_DIR . 'qa-app-format.php';
require_once QA_INCLUDE_DIR . 'qa-util-string.php';
switch ($event) {
//this gets question posts
case 'q_post':
$sendhandle=isset($handle) ? $handle : qa_lang('main/anonymous');
$this->post_tweets(
$this->build_twitter_status(
$sendhandle,
$params['title'],
$params['text'],
qa_q_path($params['postid'], $params['title'], true) //url of the questions post
)
);
break;
//this get answer posts
case 'a_post':
$sendhandle=isset($handle) ? $handle : qa_lang('main/anonymous');
$this->post_tweets(
$this->build_twitter_status(
$sendhandle,
$params['title'],
$params['text'],
qa_q_path($params['postid'], $params['title'], true, 'A') //url of the questions post
)
);
break;
//this gets comment posts
case 'c_post':
$sendhandle=isset($handle) ? $handle : qa_lang('main/anonymous');
$this->post_tweets(
$this->build_twitter_status(
$sendhandle,
$params['title'],
$params['text'],
qa_q_path($params['postid'], $params['title'], true, 'C')//url of the questions post
)
);
}
}
//This is the status message that will go to twitter
private function build_twitter_status($who, $title, $content, $url) {
return array(
'status' => array(
'message[body]' => sprintf("%s asked a new question \"%s\" on #QNA, check it out!", $who, $title),
'message[url]' => $url,
)
);
}
//This is the twitter request
function post_tweets()
{
require_once $this->directory . 'TwitterAPIExchange.php';
// Setting our Authentication Variables that we got after creating an application
$settings = array(
'oauth_access_token' => qa_opt('qa_twitter_at'),
'oauth_access_token_secret' => qa_opt('qa_twitter_ts'),
'consumer_key' => qa_opt('qa_twitter_ck'),
'consumer_secret' => qa_opt('qa_twitter_cs')
);
$url = "https://api.twitter.com/1.1/statuses/update.json";
$requestMethod = "POST";
//This is where ths post status goes
$postfields = $this->build_twitter_status();
$twitter = new TwitterAPIExchange($settings);
$tweets = $twitter->setPostfields($postfields)
->buildOauth($url, $requestMethod)
->performRequest();
return $tweets;
}
While this code works, but it only makes the posts send to twitter but not the url of the post too. i want to be able to send the post and it’s url. the problem is from the “build_twitter_status” cause that’s what’s going to be pages to $postfields
Please trying to work using TwitterAPIExchange. help me out
This code doesn’t work. It’s supposed to get the post and it’s url and send to twitter. it doesn’t show any error. the problem is from the “build_twitter_status” cause that’s what’s going to be pages to $postfields.
While this code works, but it only makes the posts send to twitter but not the url of the post too. i want to be able to send the post and it’s url. the problem is from the “build_twitter_status” cause that’s what’s going to be pages to $postfields