English 中文(简体)
最新信息——使用Abraham s twitteroauth
原标题:update_with_media using abraham s twitteroauth

I m 试图上载——用Abraham s twitteroauth图书馆(TwitterOAuth v0.2-0-beta2)。 我在基本岗位上没有问题,但当我试图把媒体包括在内时,我的反应是:

"{"request":"/1/statuses/update_with_media.json","error":"Error creating status."}"

我的媒体发布守则就是这样:

   $image = $_FILES["media"]["tmp_name"];

    $parameters = array(
         media[]   => "@{$image};type=image/jpeg;filename={$image}",
         status    => $status
      );

    if(isset($reply_id)) {
        $parameters[ in_reply_to_status_id ] = $reply_id;
    }
    $post = $twitteroauth->post( https://upload.twitter.com/1/statuses/update_with_media.json , $parameters);
    echo json_encode($post);

我已经核实,所有数据都正确发送到该书,甚至设法得到更新——即使用上述相同数据的媒体站和TumhOAuth图书馆,但由于我的植被的其他部分使用过Twitteroauth,我宁愿保持一些统一。 我也尝试了它,而没有了结,也没有发现任何区别。 任何人能否向我展示成功实施更新的实例——与使用wit子的媒体接触? 我看不出我错做什么。

问题回答

在数小时为UPDATE_WITH_MEDIA找到解决办法后,我找到了以下办法:

  • First: the PHP original library linked from Twitter Dev here does not work.

IS NOT WorkingING with UPDATE_WITH_MEDIA

基本的推论是,原有的“员额”没有“多部分”参数。 这一参数是能够发送Twiiter在文件中提出的要求:一个多部分类员额。 因此,基本法典如下:

$image_path="folder/image.jpg";

$handle = fopen($image_path, rb );
$image  = fread($handle,filesize($image_path));
fclose($handle);

$params = array(
   media[]  => "{$image};type=image/jpeg;filename={$image_path}",
   status   => "Put your message here, must be less than 117 characters!"
);
$post = $connection->post( statuses/update_with_media , $params, true);

IMPORTANT! 如果你用原始图书馆来尝试这一守则,你就会发现错误。 您必须从上述链接下载,并替换项目中的两份档案(OAuth.php和twitteroauth.php)。

我建议,你使用Fiddler2或一些类似工具,审查和比较与Twitteroauth以及tmhOAuth的通信。 你们会看到这种差异。

In my experience, this is what an HTTP POST to Twitter looks like, using update_with_media.{xml,json}. The suffix you use affects only the respponse, I believe. (Your app must set the Authorization header in a way that is specific to your app.)

你们希望获得像以下这样的职位:

POST https://upload.twitter.com/1/statuses/update_with_media.xml HTTP/1.1
Authorization: OAuth oauth_callback="oob", oauth_consumer_key="xxxxxxxxxxxx", oauth_nonce="7774328k", oauth_signature="pUYjRnccmrBYiO1j9cliETsw%2B5s%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1318300521", oauth_token="59152613-vrlZ2edX56PudQtBmpAWd3SPDt9cPyAhibO7ysl6W", oauth_version="1.0"
Content-Type: multipart/form-data; boundary=======c49479438c600bf59345e======
Host: upload.twitter.com
Content-Length: 7320
Connection: Keep-Alive

--======c49479438c600bf59345e======
Content-Disposition: form-data; name="status"

working on a Tweet tool that uses the OAuth Manager library.
--======c49479438c600bf59345e======
Content-Disposition: file; name="media[]"; filename="ThisIsAPicture.png"
Content-Type: image/png

  ...binary png data here...

--======c49479438c600bf59345e======--

我愿寄送与地位 param的卢旺达语。

如: 您在此致辞

对在2022年读过这段话的人来说,我找不到任何答案,但我设法通过把媒体上排在《成果》的头版到2版来解决。 但是,在恢复图像之后,立即放下一版。

看来,第2版端点并不完全支持媒体上载,而不知道为什么。 但是,这对我来说是完美的,希望这对一个人来说是有用的:

$connection = new TwitterOAuth(env( TWITTER_CONSUMER_KEY ), env( TWITTER_CONSUMER_SECRET ), env( TWITTER_ACCESS_TOKEN ), env( TWITTER_ACCESS_TOKEN_SECRET ));

    $result = $connection->upload( media/upload , [
         media  =>  /img/path.png ,
    ], true);

    // check here to see if img has uploaded
    var_dump($result);

    $connection->setApiVersion( 2 );

    $response = $connection->post( tweets , [
         text  =>  Test ,
         media  => [
             media_ids  => [$result->media_id_string],
        ]
    ], true);

    var_dump($response);




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签