rather than using the RT prefix to a tweet, Twitter now provides a retweeted sign on retweeted tweets. I would like this to show up on my retweeted tweets on my twitter bot... i.e. the original user information is embedded on the feed in twitter.com/user
this is the code i have so far (using API 1.1):
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$twitter->host = "http://search.twitter.com/";
$search = $twitter->get('search', array('q' => '-escort -RT -ADRTBot #abudhabi', 'count' => 5));
$twitter->host = "https://api.twitter.com/1.1/";
foreach($search->results as $tweet) {
$status = $tweet->text;
if(strlen($status) > 140) $status = substr($status, 0, 139);
$twitter->post('statuses/retweet/$tweet->id', array('status' => $status));
print "STATUS: $tweet->id $status<br>";
}
Any ideas would be gratefully received!!
The above doesn't work... and i'm still struggling to retweet using the new api 1.1.
Here is the revised code i have so far:
<?php
require_once('twitteroauth/twitteroauth.php');
define('CONSUMER_KEY', 'xxxxx');
define('CONSUMER_SECRET', 'xxxxx');
define('ACCESS_TOKEN', 'xxxxx');
define('ACCESS_TOKEN_SECRET', 'xxxxx');
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$tweets = $twitter->get("https://api.twitter.com/1.1/search/tweets.json?q=-escort%20-RT%20-ADRTBot%20abudhabi&count=5");
$twitter->host = "https://api.twitter.com/1.1/";
foreach($tweets as $tweet) {
foreach($tweet as $chirp) {
$id = $chirp->id_str;
//testing that data coming through... and it is
echo "<br>THIS IS THE ID: $id<br>";
echo "statuses/retweet/$id.json<br>";
echo "$chirp->text<br>";
$twitter->post('https://api.twitter.com/1.1/statuses/retweet/$id.json');
}
}
echo json_encode($tweets);
?>
However, it is not posting to twitter... what am i missing?
Many thanks,
R
you should have left the code alone from the original coder. Up until 2 days ago this bot actually worked but due to twitter updates on API 1.1 the bot has stopped functioning and I think it's down to the properties of search.twitter.com though to answer your question
[code]
require_once('twitteroauth.php');
define('CONSUMER_KEY', '\\');
define('CONSUMER_SECRET', '\\');
define('ACCESS_TOKEN', '\\');
define('ACCESS_TOKEN_SECRET', '\\');
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$twitter->host = "http://search.twitter.com/";
$search = $twitter->get('search',array('q' => '#abudhabi', 'another hashtag here', 'another keyword here', 'rrp' => 4));
$twitter->host = "https://api.twitter.com/1.1/";
foreach($search->results as $tweet) {
$status = 'RT #'.$tweet->from_user.' '.$tweet->text;
if(strlen($status) > 140) $status = substr($status, 0, 139);
$twitter->post('statuses/update', array('status' => $status));
}
echo "Success! Check your twitter bot for retweets!";
[/code]
Related
I am creating webhook for trello using trello api and mattzuba sdk, webhook is created successfully by using post method but there are two issues
On getting this webhook by using GET function, no results I found.
On changing in model (board id ive used) its not hitting to the callbackURL, i want some example code for callbackurl.
Here is my code of Example.php
$id = '558d029fd94e87c6230df746';
$callback_url = 'http://exampledomain.com/webhook.php';
$description = 'Webhook for board';
$webhook = array(
'idModel' => $id,
'callbackURL' => $callback_url,
'description' => $description,
);
$post = $trello2->post("tokens/$token/webhooks/?key=$key", array_filter($webhook));
print_r($post);
Here is the code of callbackurl page webhook.php
$json = file_get_contents('php://input');
$action = json_decode($json);
$sql = mysql_query("INSERT INTO trellowebhook (data) VALUES ('$action')",$con);
print_r($sql);
I have a twitter bot, where it searches for an #mention and replies to the user depending on what the user says.
It was working fine until this week, when I started getting this error:
Warning: Invalid argument supplied for foreach() in /home/reportax/public_html/reportaxi/twitterbot/config.php on line 14
I stripped down the code to the most basic form, which is the searching for the #mention and then tweeting something when it finds it, but I'm still getting this error. Any ideas?
As I mentioned before, this was working fine until this week, so I know the consumer key, secret, and all that is OK.
here's the code:
<?php
require_once('twitteroauth.php');
define('CONSUMER_KEY', 'MYKEY');
define('CONSUMER_SECRET', 'MYSECRET');
define('ACCESS_TOKEN', 'MYTOKEN');
define('ACCESS_TOKEN_SECRET', 'MYTOKENSECRET');
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$twitter->host = "http://search.twitter.com/";
$search = $twitter->get('search', array('q' => '#repor_taxi', 'rpp' => 15));
$twitter->host = "https://api.twitter.com/1/";
foreach($search->results as $tweet) {
$status = 'RT #'.$tweet->from_user.' '.$tweet->text;
if(strlen($status) > 140) $status = substr($status, 0, 139);
$twitter->post('statuses/update', array('status' => $status));
}
?
any ideas?
I had the same problem. You need update your code for twitter API 1.1.
<?php
require_once('twitteroauth.php');
define('CONSUMER_KEY', 'MYKEY');
define('CONSUMER_SECRET', 'MYSECRET');
define('ACCESS_TOKEN', 'MYTOKEN');
define('ACCESS_TOKEN_SECRET', 'MYTOKENSECRET');
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
/*The search has change a little bit */
/* Remove this 2 lines */
/* $twitter->host = "http://search.twitter.com/"; */
/* $search = $twitter->get('search', array('q' => '#repor_taxi', 'rpp' => 15)); */
/* Put this new line */
$search = $twitter->get("https://api.twitter.com/1.1/search/tweets.json?q=#repor_taxi&count=15");
/* The Search URL is https://api.twitter.com/1.1/search/tweets.json?q= */
/* Everything after is parameter */
/* You can check parameters list here: https://dev.twitter.com/docs/using-search */
/* Twitter host updated too */
$twitter->host = "https://api.twitter.com/1.1/";
foreach($search as $tweet) {
...
?>
I hope this may help you. Good luck.
I am developing an application which can send tweets to my twitter profile.
Now I need to implement retweet and delete tweet function. I implement those like following but no success. can any one help me!!
/* Delete tweet function */
$twitteroauthPost = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$token = $twitteroauthPost->getRequestToken();
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,$token['oauth_token'], $token['oauth_token_secret']);
$result = $connection->post('statuses/destroy', array('id' => $postId));
/* Retweet function */
$twitteroauthPost = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$token = $twitteroauthPost->getRequestToken();
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,$token['oauth_token'], $token['oauth_token_secret']);
$result = $connection->post('statuses/retweet', array('id' => $postId));
Then it return this
(
[request] => /1/statuses/retweet.json
[error] => Could not authenticate you.
)
This error means that the authorization header that gets sent to twitter is not correct. Since you are using a library that's been tested and is widely used I'm guessing that you have got your CONSUMER_KEY or CONSUMER_SECRET wrong. I'd just double check these.
Is there a way to get the list of retweeters ids using streaming api
REST api has "GET statuses/:id/retweeted_by/ids" for getting the list of retweeters
Streaming api has a "statuses/retweet", but is not a generally available resources.
So the idea is to use "statuses/filter" and filter based on tweet ids.
Thank you
In the results returned by the streaming API, retweeters (if any) are listed here:
$retweeters = $tweet->{'retweeted_status'}->{'activities'}->{'retweeters'};
Here's a page which shows the ids of retweeters for a stream filtered with a search for the word 'love' — make sure to use your Twitter username and password. Note that the APIs only return the first 100 retweeters.
<html><body>
<?php
echo(str_pad("START<br>",2048));
#ob_flush();
flush();
$opts = array(
'http'=>array(
'method' => "POST",
'content' => 'track=love',
'header' => "Content-Type: application/x-www-form-urlencoded\r\n"
)
);
$context = stream_context_create($opts);
$username = 'your_twitter_username';
$password = 'your_twitter_password';
while (1){
$instream = fopen('http://'.$username.':'.$password.'#stream.twitter.com/1/statuses/filter.json','r' ,false, $context);
while(! feof($instream)) {
if(! ($line = stream_get_line($instream, 20000, "\n"))) {
continue;
}else{
$tweet = json_decode($line);
$retweeters = array();
$retweeters = $tweet->{'retweeted_status'}->{'activities'}->{'retweeters'};
//We store the new post in the database, to be able to read it later
if (sizeof($retweeters) > 0) {
echo("<br><br>");
print_r($retweeters);
}
#ob_flush();
flush();
}
}
}
?>
</html></body>
I am attempting to gain three-legged Oauth access, but I can't get the first step to work. My code so far:
include("OAuth.php");
$consumer_key = "anonymous";
$consumer_secret = "anonymous";
define("URI", "http://www.google.com");
$request_token_url = URI.'/accounts/OAuthGetRequestToken?scope=https%3A%2F%2Fwww.google.com%2Fh9%2Ffeeds%2F';
$parsed = parse_url($request_token_url);
$params = array();
$oauth_consumer = new OAuthConsumer($consumer_key, $consumer_secret, NULL);
$req_req = OAuthRequest::from_consumer_and_token($oauth_consumer, NULL, "GET", $request_token_url, $params);
$sig_method = new OAuthSignatureMethod_HMAC_SHA1();
$req_req->sign_request($sig_method, $oauth_consumer, NULL);
$request = $req_req->to_url();
$session = curl_init($request);
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);
// Make the request
$response = curl_exec($session);
//Error Handling:
// there is an error while executing the request,
if (!$response) {
$response = curl_error($curl);
}
curl_close($session);
parse_str($response, $params);
$oauth_token = $params['oauth_token'];
$oauth_token_secret = $params['oauth_token_secret'];
$_SESSION['CONSUMER_KEY'] = $consumer_key;
$_SESSION['CONSUMER_SECRET'] = $consumer_secret;
$_SESSION['REQUEST_TOKEN'] = $oauth_token;
$_SESSION['REQUEST_TOKEN_SECRET'] = $oauth_token_secret;
print_r($_SESSION);
I'm using OAuth.php.
The returning array does not give me anything:
Array (
[CONSUMER_KEY] => googlecodesamples.com
[CONSUMER_SECRET] => [REQUEST_TOKEN] => [REQUEST_TOKEN_SECRET] =>
)
I found this on the Google Oauth Reference
If your application is not registered, select HMAC-SHA1 and use the following key and secret:
consumer key: "anonymous" consumer
secret: "anonymous"
I have altered the consumer_key and consumer_secret variables but the returning array remains empty.
I'm not sure what I'm doing wrong this is a basic H9 sandbox development procedure; any advice would help.
Well I have figured this one out,
When I printed the response of the curl I got a message which said:
This URL has moved here:
https://www.google.com/accounts/OAuthGetRequestToken?oauth_consumer_key=anonymous%20%20%20%20[amp;oauth_nonce]%20=%3E%20828f80d4cec64b5b6fcca5010e2aa952%20%20%20%20[amp;oauth_signature]%20=%3E%20H+WrK1WIhyFEkrHRBvjpzcVLFvs=%20%20%20%20[amp;oauth_signature_method]%20=%3E%20HMAC-SHA1%20%20%20%20[amp;oauth_timestamp]%20=%3E%201282773417%20%20%20%20[amp;oauth_version]%20=%3E%201.0%20%20%20%20[amp;scope]%20=%3E%20https://www.google.com/h9/feeds/
So once I changed the $request_token_url to this, it worked like a charm and I finally have one-leg!! two left :)