请帮助...我可以发送推文,但是当尝试上传媒体时说“丢失或无效的网址参数”
我尝试了很多定义“媒体”的方法,只有url,getfilecontent(“url”),“@”。“url”等等......
我使用亚伯拉罕图书馆(twitteroauth)
这是我的代码:
<?php
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
header('Location: ./clearsessions.php');
}
$access_token = $_SESSION['access_token'];
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $rowTwitter["twitter_token"], $rowTwitter["twitter_token_secret"]);
$msg = $_POST["texto2"];
$image = $_POST["URL"];
$parameters = array(
'media[]' => "{$image}",
'status' => "{$msg}"
);
$code = $connection->post('statuses/update_with_media', $parameters);
var_dump($code);
?>
这就是结果:
object(stdClass)#5(1){[“errors”] =&gt; array(1){[0] =&gt; object(stdClass)#6(2){[“code”] =&gt; int(195)[“message”] =&gt; string(33)“缺少或无效的url参数。” }}
编辑:你好!我添加了这段代码:
$filename = $image;
$handle = fopen($filename, "rb");
$image = fread($handle, filesize($filename));
fclose($handle);
现在这就是问题:
object(stdClass)#5(1){[“errors”] =&gt; array(1){[0] =&gt; object(stdClass)#6(2){[“code”] =&gt; int(189)[“message”] =&gt; string(22)“创建状态时出错”。 }}
答案 0 :(得分:0)
我使用修改后的库
--- --- HTML
<form action="" method="POST" enctype="multipart/form-data">
<div>
<label for="status">Tweet Text</label>
<textarea type="text" name="status" rows="5" cols="60"></textarea>
<br />
<label for="image">Photo</label>
<input type="file" name="image" />
<br />
<input type="submit" value="Submit" />
</div>
</form>
--- --- PHP
if (!empty($_FILES)) {
// we set the type and filename are set here as well
$params = array(
'media[]' => "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}",
'status' => $_POST['status']
);
$dd = $twitteroauth->post('statuses/update_with_media',$params,true);
var_dump($dd);
}
在这里下载修改过的库