update with photo in twitter

戏子无情 提交于 2019-12-12 02:19:44

问题


Afer tried a lot of times with abraham's code and other, I will read about tmhOauth, but I couldn't update the statuses with a picture. I modified with the 1.1 url this one and it doesn't works. Please somebody could help me? Thanks.

<?php

/**
 * Tweets a Twitter photo along with a message from the user whose oauth_token
 * and oauth_secret you use.
 *
 * Although this example uses your user token/secret, you can use
 * the oauth_token/secret of any user who has authorised your application.
 *
 * This example is intended to be run from the command line.
 *
 * Instructions:
 * 1) If you don't have one already, create a Twitter application on
 *      https://dev.twitter.com/apps
 * 2) From the application details page copy the consumer key and consumer
 *      secret into the place in this code marked with (YOUR_CONSUMER_KEY
 *      and YOUR_CONSUMER_SECRET)
 * 3) From the application details page copy the access token and access token
 *      secret into the place in this code marked with (A_USER_TOKEN
 *      and A_USER_SECRET)
 * 4) Update $image to point to a real image file on your computer.
 * 5) In a terminal or server type:
 *      php /path/to/here/photo_tweet.php
 *
 * @author themattharris
 */

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

// 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.
$image = '1594816618.jpg';

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

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


?>

回答1:


I had the same problem. I found that on my server, I had to specify the full file system path (NOT the URL) to the image.

For example, '/home/mydomain/public_html/image.jpg'

As soon as I did that it worked fine.



来源:https://stackoverflow.com/questions/17621133/update-with-photo-in-twitter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!