am trying to create a php script that post tweets to some users
i use that php class to do that
https://github.com/abraham/twitteroauth
but how can i post a tweet to multiple accounts in the same time
i use this code but it sand to one account only
<?php
session_start();
require_once('library/twitteroauth.php');
$ConsumerKey = "xxx";
$ConsumerSecret = "xxx";
$oauth_token = "xxx";
$oauth_token_secret = "xxx";
$connection = new TwitterOAuth($ConsumerKey, $ConsumerSecret ,$oauth_token , $oauth_token_secret);
//$twit_body = $_POST['twit_body'];
$twit_body = 'تجربة للجميع022222222';
$status = $connection->post('statuses/update', array('status' => $twit_body) );
//$status = $connection->send($twit_body);
print_r($status);
?>
You need different oAuth Tokens to achieve this. They are unique for each user.
Please go through this link: Post to multiple twitter accounts PHP
You'd need different oauth tokens, they are assigned on a per-user basis.
Related
I am trying to get the lists details from aweber account i can get all lists by hard code access keys but what if i want to fetch from database.
here is my code:
$consumerKey = env('consumerKey');
$consumerSecret = env('consumerSecret');
$user_id = \Illuminate\Support\Facades\Auth::user();
$keys = \Illuminate\Support\Facades \ DB::table('access_keys')->where('user_id','=', $user_id)->value('accessTokenKey','accessTokenSecret');
$accessKey = $keys;
$accessSecret = $keys
I am having invalid accesstoken from this query and i have saved accesskey and accesssecret into my database. when i hard code i can get all the lists but i want to fetch from database:
Any help would be appreciated!
First get Aweber API code from git:- https://github.com/aweber/AWeber-API-PHP-Library
To get lists from Aweber account , you need to follow below details:-
require_once('aweber_api/aweber_api.php');
$consumerKey = "YOUR CONSUMER KEY";
$consumerSecret = "YOUR CONSUMER SECRET";
$aweber = new AWeberAPI($consumerKey, $consumerSecret);
$accessToken = 'Access token for customer account';
$accessTokenSecret = 'access token secret for customer account';
$account = $aweber->getAccount($accessToken, $accessTokenSecret);
if($account){
foreach($account->lists as $offset => $list) {
echo $list->name;
echo $list->id;
}
}
I have registered an application in Twitter. Now I want to send every update to user from application in the form of tweets using php :
$consumer_key = 'XXXXX';
$consumer_secret = 'XXXXX';
$oauth_token = 'XXXXX';
$oauth_secret = 'XXXXX';
$connection = new TwitterOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_secret);
$connection->host = "https://api.twitter.com/1.1/";
$connection->ssl_verifypeer = TRUE;
$parameters = array('status'=>'this is a message');
$status = $connection->post('statuses/update',$parameters);
The code is working fine but it is posting tweet from user's own account to his wall which is not what I want. I want to send tweet from application to user's wall.
Hi all i developed an application for posting tweet using PHp with twitter api 1.1. But that option is only working for me only. If any one authenticated and try to send tweet using that. It's posting tweet on my wall.
How to make this generalized for anyone.
YOUR_CONSUMER_KEY = 'xxxxxxxxxxxxxx';
YOUR_CONSUMER_SECRET = 'xxxx';
$twitteroauth = new TwitterOAuth(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET);
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('http://xxxx/xxxx/getTwitterData.php');
//print_r($request_token);
$twitteroauth = new TwitterOAuth(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET, $request_token['oauth_token'], $request_token['oauth_token_secret']);
$tmessage = $_POST['message'];
$content = $twitteroauth->post('statuses/update', array('status' => $tmessage));
it's posting tweets on your wall because you're using access token and secret of the app, or you're the authenticated user. You need to log in the user you want to post for, get their access token and secret, then use consumer key, secret, user access token and user access secret to post on their behalf.
It's a bit unclear what you're trying to do, but here's a sample post action with Abraham William's library, which you're using:
require_once('twitteroauth.php');
$key = "***";
$secret = "***";
$token = "***";
$token_secret = "***";
$connection = new TwitterOAuth($key, $secret, $token, $token_secret);
$message = "whatever";
$status = $connection->post($message);
$response= $connection->http_code;
if($response !=200){
echo "ERROR";
}else{
echo "life is good";
}
I have a code, where people can post messages on the app's wall via my app
$consumerKey = '';
$consumerSecret = '';
$accessToken = '';
$accessTokenSecret = '';
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
$tweetMessage = $_POST['message'];
if(strlen($tweetMessage)<=140)
{
$tweet->post('statuses/update', array('status' => $tweetMessage));
$day = date('Y-m-d H:i:s');
mysql_query("INSERT INTO users (message,data,social) VALUES ('".$_POST['message']."','".$day."','tw')");
}
how can I make the script to post messages from users on their own walls via my app ?
is it possible?
thank you!
Actually, now that I think of it, what you probably want here is not a Twitter application at all. Since you want your visitors to post messages themselves, the correct way to do this is by using Twitter Web Intents.
I use the below code to retrieve my tweets and echo json. This works fine.
<?php
session_start();
require_once('includes/twitter/twitteroauth.php');
$twitteruser = "xxxxxx";
$notweets = 3;
$consumerkey = "xxxxxxx";
$consumersecret = "xxxxxx";
$accesstoken = "xxxxxxxx";
$accesstokensecret = "xxxxxx";
$connection = new TwitterOAuth($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);
echo json_encode($tweets);
?>
Now i want to send a tweet using the similar code but it doesnot work. I am not sure if the sending syntax is correct. so please someone help me.
<?php
session_start();
require_once('includes/twitter/twitteroauth.php'); //Path to twitteroauth library
$twitteruser = "xxxxxx";
$notweets = 3;
$consumerkey = "xxxxxxx";
$consumersecret = "xxxxxx";
$accesstoken = "xxxxxxxx";
$accesstokensecret = "xxxxxx";
// start connection
$connection = new TwitterOAuth($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
//message
$message = "Hi how are you";
//send message
$status = $connection->post('https://api.twitter.com/1.1/statuses/update.json', array('status' => $message));
?>
I was using twitteroauth.php to post tweets myself when the new API broke it. You are using the $connection->post correctly, but it appears that function does not work anymore. The easiest solution I found was to swap out the twitteroauth.php with J7mbo's twitter-api-php file for the new 1.1 API:
https://github.com/J7mbo/twitter-api-php
Here's his step-by-step instructions for using it. I think you'll be pleasantly surprised to find you can leave most of your code the same, just switch the twitteroauth calls with his function calls at the appropriate places:
Simplest PHP example for retrieving user_timeline with Twitter API version 1.1
He doesn't provide the specific example of posting a tweet, but here's what what you need for that function:
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$requestMethod = 'POST';
$postfields = array(
'status' => 'Hi how are you' );
echo $twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
With the new twitter API, you won't need to provide your username/password. The authentication token will handle everything.
Just use the example:
$connection->post('statuses/update', array('status' =>$message));
Try it
you won't need to username/password you can post via API key read the tutorial here.
http://designspicy.com/learn-how-to-post-on-twitter-using-php-and-oauth/
The issue is about enconding the value need to be enconde :
Example
$status = $connection->post('https://api.twitter.com/1.1/statuses/update.json', array('status' => rawurlencode($message)));
If you check in the library recomended https://github.com/J7mbo/twitter-api-php
That the way they encode the params