用推特中的照片更新 [英] update with photo in twitter

查看:121
本文介绍了用推特中的照片更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Afer用亚伯拉罕的代码和其他代码尝试了很多次,我将阅读有关tmhOauth的信息,但是我无法通过图片更新状态.我用1.1网址修改了这个网址,但它不起作用.请有人可以帮我吗?谢谢.

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']);
}


?>

推荐答案

我遇到了同样的问题.我发现在服务器上,我必须指定图像的完整文件系统路径(不是URL).

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.

例如'/home/mydomain/public_html/image.jpg'

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

一经发现,它就可以正常工作.

As soon as I did that it worked fine.

这篇关于用推特中的照片更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆