Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在MONGODB中插入推文 在进入循环之前,$usertimeline中有什么内容?好的。从$collection->insert($item)返回的内容var\u dumpit可以精确地检查这一点。var\u dump返回“null”。。。。我的问题的解_Php_Mongodb_Twitter - Fatal编程技术网

Php 在MONGODB中插入推文 在进入循环之前,$usertimeline中有什么内容?好的。从$collection->insert($item)返回的内容var\u dumpit可以精确地检查这一点。var\u dump返回“null”。。。。我的问题的解

Php 在MONGODB中插入推文 在进入循环之前,$usertimeline中有什么内容?好的。从$collection->insert($item)返回的内容var\u dumpit可以精确地检查这一点。var\u dump返回“null”。。。。我的问题的解,php,mongodb,twitter,Php,Mongodb,Twitter,在MONGODB中插入推文 在进入循环之前,$usertimeline中有什么内容?好的。从$collection->insert($item)返回的内容var\u dumpit可以精确地检查这一点。var\u dump返回“null”。。。。我的问题的解决方案是什么?解决方案是调试代码,发现错误并修复它var_dump($collection->insert($item);)始终不返回任何内容,它应该将某些内容打印到stdout。如果不打印任何内容,则不会执行。也许$http\u code不是

在MONGODB中插入推文
在进入循环之前,
$usertimeline
中有什么内容?好的。从
$collection->insert($item)返回的内容
var\u dump
it可以精确地检查这一点。var\u dump返回“null”。。。。我的问题的解决方案是什么?解决方案是调试代码,发现错误并修复它
var_dump($collection->insert($item);)
始终不返回任何内容,它应该将某些内容打印到stdout。如果不打印任何内容,则不会执行。也许
$http\u code
不是200?也许你的PHP死了,而你隐藏的错误?ohkkk让我看看它。thanx为你的建议。但我可以知道我的代码是否正确?
<?php
require 'app_tokens.php';
require 'tmhOAuth-master/tmhOAuth.php';
$connection = new tmhOAuth(array(
    'consumer_key' => $consumer_key,
    'consumer_secret' => $consumer_secret,
    'user_token' => $user_token,
    'user_secret' => $user_secret
));
$mongo = new Mongo();
$db = $mongo->twitter;
$collection = $db->tweets;
$screen_name = "learnmongo";
$http_code = $connection->request('GET', $connection->url('1.1/search/tweets'));
if ($http_code == 200) {
    $twitter = "http://api.twitter.com/1.1/statuses/user_timeline.json?";
    $curl = curl_init($twitter);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $usertimeline = curl_exec($curl);
    curl_close($curl);
    $usertimeline = json_decode($usertimeline);
    foreach ($usertimeline as $id => $item) {
        $collection->insert($item);
    }
}