Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.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上载到twitter(api)_Php_Html_Api_Twitter_Upload - Fatal编程技术网

将图像PHP上载到twitter(api)

将图像PHP上载到twitter(api),php,html,api,twitter,upload,Php,Html,Api,Twitter,Upload,我是PHP新手,所以请保持足够简单 我尝试用api将图像上传到twitter 当文件在我的服务器上时,我已经可以将一个图像发布到twitter(test.jpg),但用户必须能够直接将其上传到twitter 我该怎么做 我在tweet.html中有这个代码 <form action="photo_tweet.php" method="post"> <p>tweet: <input type="text" name="tweet" /></p>

我是PHP新手,所以请保持足够简单

我尝试用api将图像上传到twitter

当文件在我的服务器上时,我已经可以将一个图像发布到twitter(test.jpg),但用户必须能够直接将其上传到twitter

我该怎么做

我在tweet.html中有这个代码

<form action="photo_tweet.php" method="post">
    <p>tweet: <input type="text" name="tweet" /></p>
    <input type="file" name="image" id="image"/>
    <input type="submit" name="submit" value="Submit" />
</form>

推特:

我在“photo_tweet.php”中有这段代码

<?php

/**
 */

require '../tmhOAuth.php';
require '../tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array(
  'consumer_key'    => 'xxxxxxxxxxxxxx',
  'consumer_secret' => 'xxxxxxxxxxxxxx',
  'user_token'      => 'xxxxxxxxxxxxxx',
  'user_secret'     => 'xxxxxxxxxxxxxx',
));

// we're using a hardcoded image path here. You can easily replace this with
// an uploaded image - see images.php in the examples folder for how to do this
// 'image = "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}",

// this is the jpeg file to upload. It should be in the same directory as this file.
    $tweetmessage = $_POST['tweet'];
    $image = 'test.jpg';

$code = $tmhOAuth->request(
  'POST',
  'https://upload.twitter.com/1/statuses/update_with_media.json',
  array(
    'media[]'  => "@{$image};type=image/jpeg;base64;filename={$image}",
    'status'   => $tweetmessage ,
  ),
  true, // use auth
  true  // multipart
);

if ($code == 200) {
  tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
} else {
  tmhUtilities::pr($tmhOAuth->response['response']);
}

如果你想先绕过上传到服务器上的图像,那么你需要使用他们的javascript api,如果他们有一个允许通过它发布图像的api

否则,它会在注释中告诉您如何操作

// we're using a hardcoded image path here. You can easily replace this with
// an uploaded image - see images.php in the examples folder for how to do this
// 'image = "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}",

$\u FILES
是一个全局变量,用于保存用户通过推特表单提交的上传图像的相关信息。

如果您想先绕过上传到服务器的图像,则需要使用他们的javascript api(如果他们有一个允许通过该api发布图像的api)

否则,它会在注释中告诉您如何操作

// we're using a hardcoded image path here. You can easily replace this with
// an uploaded image - see images.php in the examples folder for how to do this
// 'image = "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}",

$\u FILES
是一个全局变量,用于保存用户通过推特表单提交的上传图像的相关信息。

我认为Evert是最简单的方法,如下所示。有一个上传图像页面。此页面临时将图像上载到服务器,因为在上载到服务器后,它会使用存储在变量中的图像文件名重定向。然后动态上传到Twitter,5分钟后从你的网站上删除

要点:

  • 用户临时上传到您的站点
  • 重定向到您站点上的Twitter上载页面
  • 上传你以前的$image
  • 然后,对其进行计时,使其在5分钟内从您的站点删除
注:

  • 如果你想拥有一个优秀的Twitter客户端,请将所有图片上传。更好的安全性
  • 另外,我不知道你是否知道,但是如果你的Twitter客户端发布了一个到a.jpg的直接链接,它将与pic.Twitter.com上的图像一样工作
  • 最后,我认为您已经掌握了诀窍,但作为一名刚起步的PHP开发人员,我建议您选择一个较小的项目;)
祝你好运!
拉科塔·卢斯蒂格(Lakota Lustig)

我在想,埃弗特,对你来说,这是最简单的方法,如下所示。有一个上传图像页面。此页面临时将图像上载到服务器,因为在上载到服务器后,它会使用存储在变量中的图像文件名重定向。然后动态上传到Twitter,5分钟后从你的网站上删除

要点:

  • 用户临时上传到您的站点
  • 重定向到您站点上的Twitter上载页面
  • 上传你以前的$image
  • 然后,对其进行计时,使其在5分钟内从您的站点删除
注:

  • 如果你想拥有一个优秀的Twitter客户端,请将所有图片上传。更好的安全性
  • 另外,我不知道你是否知道,但是如果你的Twitter客户端发布了一个到a.jpg的直接链接,它将与pic.Twitter.com上的图像一样工作
  • 最后,我认为您已经掌握了诀窍,但作为一名刚起步的PHP开发人员,我建议您选择一个较小的项目;)
祝你好运!
Lakota Lustig

我知道,但正如我所说,我对php完全陌生,所以我不知道如何使用它。。你能给我一个复制粘贴的东西吗我试过这样做,但我总是会犯一些错误…我知道,但正如我所说,我对php完全陌生,所以我不知道如何使用它。。你能给我一个复制粘贴的东西吗我试过这么做,但我总是会犯一些错误…Thx Lakota,我想我会这么做^^^(但5分钟后怎么删除它?)Thx Lakota,我想我会这么做^^(但5分钟后怎么删除它?)