0

I am using the reference from Inserting data from Twitter API into a MySQL Database using php to insert tweets into mysql database. But i am getting PHP "Fatal error: Uncaught mysqli_sql_exception: Column 'id_str' cannot be null". Even if I use another variable like 'created_at', I am getting the same error.

Is it because the json is not properly parsed? Below is the code snippet:

$twitter = new TwitterAPIExchange($settings);
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q='.urlencode("#f1").'&count=10'.'&tweet_mode=extended';
$requestMethod = 'GET';

$tweets = json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(),$assoc = TRUE);
foreach($tweets as $tweet){
    $created_at = $tweet['created_at'];
    $id_str = $tweet['id_str'];

    <PHP PREPARED STATEMENTs FOR INSERTING etc>
}

1 Answer 1

0

Managed to resolved it:

Have to use:

foreach($tweets['statuses'] as $tweet)

instead of

foreach($tweets as $tweet)

Not sure why it is returned this way though. But it works!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.