【问题标题】:PHP inserting tweets into mysqlPHP将推文插入mysql
【发布时间】:2020-01-27 08:57:33
【问题描述】:

我正在使用来自Inserting data from Twitter API into a MySQL Database using php 的引用将推文插入 mysql 数据库。但我收到 PHP“致命错误:未捕获的 mysqli_sql_exception:列 'id_str' 不能为空”。即使我使用另一个变量,如“created_at”,我也会遇到同样的错误。

是不是因为没有正确解析json?下面是sn-p的代码:

$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>
}

【问题讨论】:

    标签: php mysql json twitter


    【解决方案1】:

    设法解决它:

    必须使用:

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

    而不是

    foreach($tweets as $tweet)
    

    不知道为什么它会以这种方式返回。但它有效!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-05
      • 2011-11-10
      • 2011-04-27
      • 1970-01-01
      • 1970-01-01
      • 2012-09-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多