I can think of several reasons.
- Do you have the token created for the application?
- You have the file of
authorization?
I leave the functions that I have created to tweet, What I do not remember well is if you associate the phone to the twitter account, but I think it did not leave
function tinyurl($url_larga){
$tiny = "http://api.bit.ly/v3/shorten?login=o_30ods7tgcl&apiKey=R_9d2e154e3e593244e0ecf67e54ae5b18&format=txt&longUrl=".$url_larga;
$sesion = curl_init();
curl_setopt ( $sesion, CURLOPT_URL, $tiny );
curl_setopt ( $sesion, CURLOPT_RETURNTRANSFER, 1 );
$url_tiny = curl_exec ( $sesion );
curl_close( $sesion );
return($url_tiny);
}
//declaramos la función que realiza la conexión a tu aplicación de twitter
function getConnectionWithAccessToken() {
$connection = new TwitterOAuth(_CONSUMER_KEY, _CONSUMER_SECRET,_OAUTH_TOKEN, _OAUTH_TOKEN_SECRET);
return $connection;
}
function twittear($mensaje,$link)
{
$hastag='' //Hastag de tu twitter;
if ($link!=''){ //Por si quieres los enlaces acortarlos con bit.ly, necesita registro
$bit=tinyurl($link); //reducimos el link con la api de bit.ly
$quedan=(140-strlen($bit))-4; // calculo los caracteres restantes que me quedan para publicar restando los puntos suspensivo
$mensaje=substr(utf8_encode($mensaje),0,$quedan). ' ' . $bit . ' ' . $hastag; // corto el mensaje en caso de que sea muy largo
} else{
$mensaje=$mensaje . ' ' . $hastag; // corto el mensaje en caso de que sea muy largo
//$mensaje=$mensaje . ' ' . $hastag;
}
ini_set('display_errors', 1);
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "",
'oauth_access_token_secret' => "",
'consumer_key' => "",
'consumer_secret' => ""
);
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$requestMethod = 'POST';
/** POST fields required by the URL above. See relevant docs as above **/
$postfields = array( 'status' => $mensaje, );
/** Perform a POST request and echo the response **/
$twitter = new TwitterAPIExchange($settings);
return $twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest();
}