php - 使用 PHP 在 Twitter 上上传图片

标签 php web-services twitter twitter-oauth

我如何使用 consumer_keyconsumer_secretTwitter Wall 上上传图片而不使用 PHP 登录?

请帮助我,非常感谢。

最佳答案

好吧,我得到了答案,下载 Twitter Api用于 php 并创建一个函数。

function image_upload(){    

    define( 'YOUR_CONSUMER_KEY' , 'your twitter app consumer key');
    define( 'YOUR_CONSUMER_SECRET' , 'your twitter app consumer key secret');

    require ('twitt/tmhOAuth.php');
    require ('twitt/tmhUtilities.php');

    $tmhOAuth = new tmhOAuth(array(
             'consumer_key'    => "YOUR_CONSUMER_KEY",
             'consumer_secret' => "YOUR_CONSUMER_SECRET",
             'user_token'      => "YOUR_OAUTH_TOKEN",
             'user_secret'     => "YOUR_OAUTH_TOKEN_SECRET",
    ));

    $image = 'image.jpg';

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

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

关于php - 使用 PHP 在 Twitter 上上传图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9823169/

相关文章:

xml - 佣金明细服务 (REST)

eclipse - 在 Apache Tomcat 7 上运行的 Axis2 WebService 问题

eclipse - 具有相同路径错误的多个上下文使用 Tomcat 在 Eclipse 中运行 Web 服务

php - Zend Framework - 从 View 访问 View Helper

php - 不支持 PDO 远程主机文件访问

python - 使用仅应用程序身份验证时,Twitter API 为 GET api/帮助/语言返回 HTTP 220

ios - Firebase 身份验证 Twitter API 登录 "Nothing to see here"

php - 如何用php从json数组中提取数据?

php - 如何从学说中的连接表中检索结果

php - 如何在 Sphinx 的一个索引中使用多个来源?