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.
Related
I'm trying to do something very simple, find a Twitter share count for a given url. But with this new API, it has been rather difficult.
I'm writing this in PHP and I'm using the abraham/twitteroauth API.
At first I was using a url like this...
$tweets = $twitter->get("https://api.twitter.com/1.1/search/tweets.json");
as is show in the documentation here https://dev.twitter.com/rest/reference/get/search/tweets
However that continually resulted in 404's. So I changed the structure of my code according to this post Twitter API returning Error: 34 (404)
But now all I'm getting is 401's. That's Twitters error code 32, "Could not authenticate you."
And yes I've checked and double checked all my tokens and secrets. I've also tried things like adding a value to the callback url field.
Below is my code...
case 'twitter':
$consumerKey = '###';
$consumerSecret = '###';
$oauthToken = '###';
$oauthTokenSecret = '###';
$twitter = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret);
$tweets = $twitter->get('search/tweets', ['q' => 'post_url_goes_here']);
$count = "I'll figure out how to sort this data later";
$response[$service] = $count ? $count : 0;
break;
Anyone else run into this problem?
Thanks!
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.
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.
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 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