Help us understand the problem. What is going on with this article?

PHPからTwitterに投稿する

More than 3 years have passed since last update.

やりたいこと

PHPスクリプトからTwitterに任意の文字列を投稿したい。
今後のために、できるだけ汎用性を持たせたい。
スクリプトやライブラリをポン置きで使えるようにしたい。

動作確認環境、使用ライブラリ等

サンプルコード

tweettest.php
<?php
require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;

$consumerKey = "your consumer key";
$consumerSecret = "your consumer secret";
$accessToken = "your access token";
$accessTokenSecret = "your access token secret";

$twitter = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);

$result = $twitter->post(
        "statuses/update",
        array("status" => "本日ハ晴天ナリ")
);

if($twitter->getLastHttpCode() == 200) {
    // ツイート成功
    print "tweeted\n";
} else {
    // ツイート失敗
    print "tweet failed\n";
}

簡単な解説

コンシューマ(API)キーやアクセストークンは、Twitter Appを作成したときにもらえる。
あとは、TwitterOAuthのお作法に従えばOK

所感

え?これだけでいいの?

案外好評のようなので、他のメソッドについてもテストしてまとめました。
よろしければご覧ください。
http://qiita.com/kumasun/items/70f035a7d214d69d62c1

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした