• <legend id='z9Ggm'><style id='z9Ggm'><dir id='z9Ggm'><q id='z9Ggm'></q></dir></style></legend>
    <tfoot id='z9Ggm'></tfoot>
    • <bdo id='z9Ggm'></bdo><ul id='z9Ggm'></ul>

    <small id='z9Ggm'></small><noframes id='z9Ggm'>

      1. <i id='z9Ggm'><tr id='z9Ggm'><dt id='z9Ggm'><q id='z9Ggm'><span id='z9Ggm'><b id='z9Ggm'><form id='z9Ggm'><ins id='z9Ggm'></ins><ul id='z9Ggm'></ul><sub id='z9Ggm'></sub></form><legend id='z9Ggm'></legend><bdo id='z9Ggm'><pre id='z9Ggm'><center id='z9Ggm'></center></pre></bdo></b><th id='z9Ggm'></th></span></q></dt></tr></i><div id='z9Ggm'><tfoot id='z9Ggm'></tfoot><dl id='z9Ggm'><fieldset id='z9Ggm'></fieldset></dl></div>

        推特 API -&gt;用 php 更新个人资料 bg 图像

        Twitter API -gt; updating profile bg image with php(推特 API -gt;用 php 更新个人资料 bg 图像)

          <tbody id='Y1p7A'></tbody>

        1. <tfoot id='Y1p7A'></tfoot>
        2. <i id='Y1p7A'><tr id='Y1p7A'><dt id='Y1p7A'><q id='Y1p7A'><span id='Y1p7A'><b id='Y1p7A'><form id='Y1p7A'><ins id='Y1p7A'></ins><ul id='Y1p7A'></ul><sub id='Y1p7A'></sub></form><legend id='Y1p7A'></legend><bdo id='Y1p7A'><pre id='Y1p7A'><center id='Y1p7A'></center></pre></bdo></b><th id='Y1p7A'></th></span></q></dt></tr></i><div id='Y1p7A'><tfoot id='Y1p7A'></tfoot><dl id='Y1p7A'><fieldset id='Y1p7A'></fieldset></dl></div>
          <legend id='Y1p7A'><style id='Y1p7A'><dir id='Y1p7A'><q id='Y1p7A'></q></dir></style></legend>
                • <bdo id='Y1p7A'></bdo><ul id='Y1p7A'></ul>

                  <small id='Y1p7A'></small><noframes id='Y1p7A'>

                  本文介绍了推特 API -&gt;用 php 更新个人资料 bg 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  到目前为止,我一直在尝试使用 php 通过 twitter api 更新 twitter 个人资料 bg 图像......但没有成功

                  So far I have been trying to update the twitter profile bg image thr the twitter api with php... and without success

                  网上很多例子,包括这个:
                  通过 API 更新 Twitter 背景
                  还有这个
                  Twitter后台上传API和多表单数据
                  根本不起作用,大多数人在没有实际测试代码的情况下抛出答案.

                  Many examples on the web, including this one:
                  Updating Twitter background via API
                  and this one
                  Twitter background upload with API and multi form data
                  do not work at all, most ppl throw out answers without actually testing the code.

                  我发现直接将图片提交到twitter.com thr html表单,它会工作:

                  I found that directly submit the image to the twitter.com thr html form, it will work:

                  <form action="http://twitter.com/account/update_profile_background_image.xml" enctype="multipart/form-data" method="post">
                      File: <input type="file" name="image" /><br/>
                      <input type="submit" value="upload bg">
                  </form>
                  

                  (尽管浏览器会提示您输入 twitter 帐户的用户名和密码)

                  (although the browser will prompt you for the twitter account username and password)

                  但是,如果我想使用 php 进行相同的过程,它会失败

                  However, if I want to go thr the same process with php, it fails

                  <?php
                  if( isset($_POST["submit"]) ) {
                  
                      $target_path = "";
                      $target_path = $target_path . basename( $_FILES['myfile']['name']); 
                  
                      if(move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
                          // "The file ".  basename( $_FILES['myfile']['name']). " has been uploaded<br/>";
                      } else{
                          // "There was an error uploading the file, please try again!<br/>";
                      }
                  
                      $ch = curl_init('http://twitter.com/account/update_profile_background_image.xml');
                      curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
                      curl_setopt($ch, CURLOPT_USERPWD, $_POST['name'] . ':' . $_POST['pass']);
                      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
                      curl_setopt($ch, CURLOPT_TIMEOUT, 1);
                      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                      curl_setopt($ch, CURLOPT_POST, 1);
                      curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => base64_encode(file_get_contents($target_path))));
                  
                      $rsp = curl_exec($ch);
                      echo "<pre>" . str_replace("<", "&lt;", $rsp) . "</pre>";
                  
                  }
                  ?>
                  <form enctype="multipart/form-data" method="post">
                  <input type="hidden" name="submit" value="1"/>
                  name:<input type="text" name="name" value=""/><br/>
                  pass:<input type="password" name="pass" value=""/><br/>
                  File: <input type="file" name="myfile" /><br/>
                  <input type="submit" value="upload bg">
                  </form>
                  

                  这段代码的奇怪之处在于..它成功返回了 twitter XML,没有更新了个人资料背景图像.所以最后还是失败了.

                  The strange thing of this code is that.. it successfully returns the twitter XML, WITHOUT having the profile background image updated. So at the end it still fails.

                  非常感谢您阅读本文.如果您能提供帮助,那就太好了.请在抛出答案之前先测试您的代码,非常感谢.

                  Many thanks for reading this. It will be great if you can help. Please kindly test your code first before throwing out answers, many many thanks.

                  推荐答案

                  这对我有用(调试遗留的东西):

                  This is what works for me (debug stuff left in):

                  $url      = 'http://twitter.com/account/update_profile_background_image.xml';
                  $uname    = 'myuname';
                  $pword    = 'mypword';
                  $img_path = '/path/to/myimage.jpg';
                  $userpwd  = $uname . ':' . $pword;
                  $img_post = array('image' => '@' . $img_path . ';type=image/jpeg',
                                    'tile'  => 'true');
                  
                  $opts = array(CURLOPT_URL => $url,
                                CURLOPT_FOLLOWLOCATION => true,
                                CURLOPT_RETURNTRANSFER => true,
                                CURLOPT_HEADER => true,
                                CURLOPT_POST => true,
                                CURLOPT_POSTFIELDS => $img_post,
                                CURLOPT_HTTPAUTH => CURLAUTH_ANY,
                                CURLOPT_USERPWD => $userpwd,
                                CURLOPT_HTTPHEADER => array('Expect:'),
                                CURLINFO_HEADER_OUT => true);
                  
                  $ch = curl_init();
                  curl_setopt_array($ch, $opts);
                  $response = curl_exec($ch);
                  $err      = curl_error($ch);
                  $info     = curl_getinfo($ch);
                  curl_close($ch);
                  
                  echo '<pre>';
                  echo $err . '<br />';
                  echo '----------------' . '<br />';
                  print_r($info);
                  echo '----------------' . '<br />';
                  echo htmlspecialchars($response) . '<br />';
                  echo '</pre>';
                  

                  这篇关于推特 API -&gt;用 php 更新个人资料 bg 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  PHP Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)
                      <tbody id='YTfCe'></tbody>
                    <legend id='YTfCe'><style id='YTfCe'><dir id='YTfCe'><q id='YTfCe'></q></dir></style></legend>
                      <tfoot id='YTfCe'></tfoot>

                      <small id='YTfCe'></small><noframes id='YTfCe'>

                        <bdo id='YTfCe'></bdo><ul id='YTfCe'></ul>

                          <i id='YTfCe'><tr id='YTfCe'><dt id='YTfCe'><q id='YTfCe'><span id='YTfCe'><b id='YTfCe'><form id='YTfCe'><ins id='YTfCe'></ins><ul id='YTfCe'></ul><sub id='YTfCe'></sub></form><legend id='YTfCe'></legend><bdo id='YTfCe'><pre id='YTfCe'><center id='YTfCe'></center></pre></bdo></b><th id='YTfCe'></th></span></q></dt></tr></i><div id='YTfCe'><tfoot id='YTfCe'></tfoot><dl id='YTfCe'><fieldset id='YTfCe'></fieldset></dl></div>