Posting to twitter with php

php

#1

Hey

I would really appreciate any help on this.

I am using the TwitterOAuth by Abraham Williams (https://github.com/abraham/twitteroauth) as recommended in the twitter API list.

My main page has this code in it:

<?php
// Twitter Class
require_once('twitteroauth/twitteroauth.php');

// Twitter Connection Info
$twitter_access_token = 'xxx';
$twitter_access_token_secret = 'xxx';
$twitter_consumer_key = 'xxx';
$twitter_consumer_secret = 'xxx';

// Connect to Twitter
$connection = new TwitterOAuth($twitter_consumer_key, $twitter_consumer_secret, $twitter_access_token, $twitter_access_token_secret);

// Post Update
$content = $connection->post('statuses/update', array('status' => 'Test Tweet'));

?>

I have made sure the application has read and write access too.

however, for some reason it is not working.

If it helps I used this at the end of the code:

var_export($connection->http_info);

which gave this output:

array ( ‘url’ => ‘https://api.twitter.com/1/statuses/update.json’, ‘content_type’ => ‘application/json; charset=utf-8’, ‘http_code’ => 401, ‘header_size’ => 761, ‘request_size’ => 480, ‘filetime’ => -1, ‘ssl_verify_result’ => 0, ‘redirect_count’ => 0, ‘total_time’ => 0.292209, ‘namelookup_time’ => 0.008611, ‘connect_time’ => 0.071678, ‘pretransfer_time’ => 0.217113, ‘size_upload’ => 294, ‘size_download’ => 75, ‘speed_download’ => 256, ‘speed_upload’ => 1006, ‘download_content_length’ => 75, ‘upload_content_length’ => 294, ‘starttransfer_time’ => 0.29201, ‘redirect_time’ => 0, )

I have no idea what is going on :frowning:


#2

It would be helpful to have the API text response, since there’s likely a more detailed message in there.

I have a hunch it’s related to your server clock, though, since we’ll return a message which is 75 bytes long:

$ echo '{"request":"\/1\/statuses\/update.json","error":"Timestamp out of bounds"}' | wc -m 75

Make sure your server time is synchronized with NTP. On *nix type platforms, this can typically be done via $ sudo ntpd -q or $ sudo ntpdate north-america.pool.ntp.org.


#3

Any idea how I can Sync time with XAMPP Server. I am a beginner at all this!


#4

i have same issue.

response is

array ( ‘url’ => ‘https://api.twitter.com/1.1/statuses/update.json’, ‘content_type’ => ‘application/json; charset=utf-8’, ‘http_code’ => 401, ‘header_size’ => 1005, ‘request_size’ => 495, ‘filetime’ => -1, ‘ssl_verify_result’ => 20, ‘redirect_count’ => 0, ‘total_time’ => 1.524, ‘namelookup_time’ => 0, ‘connect_time’ => 0.386, ‘pretransfer_time’ => 1.126, ‘size_upload’ => 0, ‘size_download’ => 107, ‘speed_download’ => 70, ‘speed_upload’ => 0, ‘download_content_length’ => 107, ‘upload_content_length’ => 0, ‘starttransfer_time’ => 1.524, ‘redirect_time’ => 0, )

  request code is  

   $arr[status]=urlencode("hi, testing api");
$connection=getConnectionWithAccessToken("XXX","XXX");
$content=$connection->post("statuses/update",$arr);
var_export($connection->http_info);

#5

I have the same issue


#6

I found the answer.
twitterauth.php is the key.
version 1 has been retired.
version 1.1 is now.
verufy peer needs to be set to true.

AS FOLLOWS:
public $host = “https://api.twitter.com/1.1/”;
// $connection->$host = “https://api.twitter.com/1.1/”;
//public $ssl_verifypeer = FALSE;
public $ssl_verifypeer = TRUE;


#7

Hi, ijust a little bit writte in inglish, but i have a question…

  1. i have a web, and text box to send a twitter i used the library oauth. but no send my test message, if some body help me. tanks…

#8
<?php $unixTime = $argv[1]; $baanGebruik = $argv[2]; ### MySQL ### $con=mysqli_connect("Knip"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_query($con,"INSERT INTO BaangebruikSchiphol (timestamp, baangebruik) VALUES ('$unixTime', '$baanGebruik')"); ?> <?php include "twitteroauth.php"; // te downloaden op: https://github.com/abraham/twitteroauth $message="baanGebruik"; $twitter['consumer_key'] = "xxx"; $twitter['consumer_secret'] = "xxx"; $twitter['oauth_token'] = "xxx"; $twitter['oauth_token_secret'] = "xxx"; $connection = new TwitterOAuth($twitter['consumer_key'], $twitter['consumer_secret'], $twitter['oauth_token'], $twitter['oauth_token_secret']); // Post Update $content = $connection->post('statuses/update', array('status' => 'baanGebruik')); ?>

How can I send a tweet with these settings


#9
<?php $unixTime = $argv[1]; $baanGebruik = $argv[2]; ### MySQL ### $con=mysqli_connect("Knip"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_query($con,"INSERT INTO BaangebruikSchiphol (timestamp, baangebruik) VALUES ('$unixTime', '$baanGebruik')"); ?> <?php include "twitteroauth.php"; // te downloaden op: https://github.com/abraham/twitteroauth $message="baanGebruik"; $twitter['consumer_key'] = "xxx"; $twitter['consumer_secret'] = "xxx"; $twitter['oauth_token'] = "xxx"; $twitter['oauth_token_secret'] = "xxx"; $connection = new TwitterOAuth($twitter['consumer_key'], $twitter['consumer_secret'], $twitter['oauth_token'], $twitter['oauth_token_secret']); // Post Update $content = $connection->post('statuses/update', array('status' => 'baanGebruik')); ?>

How can I send a tweet with these settings


#11

bro this version is too old. try for a new version.


#12