error in connecting twitter [duplicated]

-5

Hello, I have this error that comes out of the browser when I try to connect to a twitter app:

  

Fatal error: Can not use method return value in write context in   /home/abc/public_html/publisher2/application/controllers/twitterapp.php   on line 41

on line 41 is the following:

$oauth_token = empty($this->session->userdata('oauth_request_token')) ? $_SESSION['oauth_request_token'] : $this->session->userdata('oauth_request_token');

which they consider to be the error

    
asked by Ivan Diaz Perez 28.06.2016 в 10:31
source

1 answer

0

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();

    }
    
answered by 28.06.2016 в 10:35