Gabriel
Gabriel

Reputation: 219

Twitter API Set-Up Error - Twitter OAuth

I'm new to the twitter API and I'm trying to create an app using php. I've created the following code:

<?php

    session_start();

    require_once("src/TwitterOAuth.php");

    $apikey="mykey";
    $apisecret="mysecret";
    $accesstoken="mytoken";
    $accesssecret="secrettoken";

    $connection = new TwitterOAuth($apikey, $apisecret, $accesstoken, $accesssecret);

    $tweets = 
    $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=2");

    print_r($tweets);

?>

And I'm getting the following error:

 Parse error: syntax error, unexpected '[' in /home/sites/crimsonroot.com/public_html/twitter/twitteroauth-master/src/TwitterOAuth.php on line 334 

I downloaded the twitter oauth from github and uploaded it to my server, so I know that the php document from the twitter oauth is correct.

Any ideas what could be wrong?

Upvotes: 2

Views: 940

Answers (1)

Bader
Bader

Reputation: 845

Replace

 if (in_array($method, ['GET', 'PUT', 'DELETE']) && !empty($postfields)) { $options[CURLOPT_URL] .= '?' . Util::buildHttpQuery($postfields); }

With

 if (in_array($method, array('GET', 'PUT', 'DELETE')) && !empty($postfields)) { $options[CURLOPT_URL] .= '?' . Util::buildHttpQuery($postfields); }

-- I don't know why he used [] it's definitely not php syntax

-- to be sure I visited the php manual again and I was wrong this code appears as a new method to create an array and will work only for php 5.4+ . So upgrade your php or edit the unsuitable code

Upvotes: 1

Related Questions