Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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 检索用户';s tweet并插入数据库_Php_Sql_Twitter_Oauth_Echo - Fatal编程技术网

Php 检索用户';s tweet并插入数据库

Php 检索用户';s tweet并插入数据库,php,sql,twitter,oauth,echo,Php,Sql,Twitter,Oauth,Echo,我正在使用以下代码将图像上载到我的rackspace cdn帐户。上传工作正常。假设,我从tweetbot发了一张照片,它会自动上传到我的rackspace cdn。我想做的是,检索我在推特上发的消息,并将消息和照片链接插入数据库中 以下是我到目前为止所做的 $oauthecho = new TwitterOAuthEcho(); $oauthecho->userAgent = 'dpkgme test app'; $oauthecho->setCredentialsFromRequ

我正在使用以下代码将图像上载到我的rackspace cdn帐户。上传工作正常。假设,我从tweetbot发了一张照片,它会自动上传到我的rackspace cdn。我想做的是,检索我在推特上发的消息,并将消息和照片链接插入数据库中

以下是我到目前为止所做的

$oauthecho = new TwitterOAuthEcho();
$oauthecho->userAgent = 'dpkgme test app';
$oauthecho->setCredentialsFromRequestHeaders();

if ($oauthecho->verify()) {      

 // Verification was a success, we should be able to access the user's Twitter info    from the responseText.
 $userInfo = json_decode($oauthecho->responseText, true);
 $twitterId = isset($userInfo['id']) ? $userInfo['id'] : null;
 $tweet = isset($userInfo['message']) ? $userInfo['message'] : null;

                    error_reporting(E_ALL);
                    ini_set('display_errors', 1);

                    // include the API
                    require("cloudfiles.php") ;

                    // cloud info
                    $username = 'username'; // username
                    $key ='apikey' ; // api key
                    $container = 'container'; // container name

                    ob_start();


                    $localfile = $_FILES['media']['tmp_name'];
                    $filename = $_FILES['media']['name'];
                    $nf = time().'-'.$filename; 


                    ob_flush();

                    // Connect to Rackspace
                    $auth = new CF_Authentication($username, $key);
                    $auth->authenticate();
                    $conn = new CF_Connection($auth);

                    // Get the container we want to use
                    $container = $conn->create_container($container);

                    // store file information

                    ob_flush();

                    // upload file to Rackspace
                    $object = $container->create_object($nf);
                    $object->load_from_filename($localfile);

                    $uri = $container->make_public();
                    //print "Your URL is: " . $object->public_uri();

                    $imagePageUrl = $object->public_uri();


                    ob_end_flush();


                    echo '<mediaurl>http://url/'.$nf.'</mediaurl>';

                    $link = 'http://url/'.$nf ; 


                    $con = mysql_connect("localhost","username","password");
                    if (!$con)
                         {
                             die('Could not connect: ' . mysql_error());
                         }

                    mysql_select_db("database", $con);

                    mysql_query("INSERT INTO photo (link)VALUES ('$link','$tweet')");


                    mysql_close($con);

 } else {
   // verification failed, we should return the error back to the consumer
   $response = json_decode($oauthecho->responseText, true);      
   $message = isset($response['error']) ? $response['error'] : null;      
    if (!headers_sent())
    header('HTTP/1.0 ' . $oauthecho->resultHttpCode);
   echo $message;
  } 
$OAutecho=新推特OAutecho();
$oauthecho->userAgent='dpkgme测试应用';
$oauthecho->setCredentialsFromRequestHeaders();
如果($oauthecho->verify()){
//验证成功了,我们应该能够从responseText访问用户的Twitter信息。
$userInfo=json_decode($OAutecho->responseText,true);
$twitterId=isset($userInfo['id'])?$userInfo['id']:null;
$tweet=isset($userInfo['message'])?$userInfo['message']:null;
错误报告(E_全部);
ini设置(“显示错误”,1);
//包括API
需要(“cloudfiles.php”);
//云信息
$username='username';//username
$key='apikey';//api密钥
$container='container';//容器名称
ob_start();
$localfile=$\u文件['media']['tmp\u名称'];
$filename=$_文件['media']['name'];
$nf=time().'-'.$filename;
ob_flush();
//连接到机架空间
$auth=新的CF\U身份验证($username,$key);
$auth->authenticate();
$conn=新的CF\U连接($auth);
//获取我们要使用的容器
$container=$conn->create_container($container);
//存储文件信息
ob_flush();
//将文件上载到Rackspace
$object=$container->create_对象($nf);
$object->load_from_filename($localfile);
$uri=$container->make_public();
//打印“您的URL是:”。$object->public_uri();
$imagePageUrl=$object->public_uri();
ob_end_flush();
回声'http://url/“.$nf.”;
$link='1http://url/“.$nf;
$con=mysql_connect(“本地主机”、“用户名”、“密码”);
如果(!$con)
{
die('无法连接:'.mysql_error());
}
mysql_select_db(“数据库”$con);
mysql_查询(“插入照片(链接)值('$link','$tweet')”;
mysql_close($con);
}否则{
//验证失败,我们应该将错误返回给使用者
$response=json_decode($OAutecho->responseText,true);
$message=isset($response['error'])?$response['error']:null;
如果(!headers_sent())
标题('HTTP/1.0'$oauthecho->resultHttpCode);
回声$信息;
} 

我上传了一些照片。上传工作正常,url返回到tweetbot。但是,没有任何内容附加到我的数据库中。请提供帮助

您尝试插入两个字段,但仅声明一个字段名:

INSERT INTO photo (link)VALUES ('$link','$tweet')
您需要执行以下操作:

INSERT INTO photo (link, tweet) VALUES ('$link','$tweet')

您可以使用
mysql\u error
在下次查看此信息

您没有检查
mysql\u error()
的输出。。。