LoginSignup
3
4

More than 5 years have passed since last update.

Visual Studio 2017からPHPでツイートするアプリ開発(twitteroauth)

Posted at

Visual Studio 2017でTwitterにツイートするアプリをPHPで開発してみました。

PHPでツイートする手順はこちらを参考にさせていただきました。
http://qiita.com/tsunet111/items/9309801cd3e3bcf6e32a

環境

Windows 7 Professional SP1 64bit
Visual Studio 2017 Community
PHP Tools for Visual Studio v1.23.9750

環境構築やPHPプロジェクトの作成はこちらを参考にしてください。
http://qiita.com/akabei/items/70fafaef7b86afb5a7ec

プロジェクト作成

新しいプロジェクトで「PHP Console Project」を作成します。

aa.png

twitteroauthパッケージインストール

プロジェクトのReferencesを右クリックして「Install New Composer Packages...」を選択します。

aaa.png

ダイアログが表示されたら左上のテキストボックスに「twitteroauth」を入力するとリストに「abraham/twitteroauth」が表示されるので、それを選択してInstall Packageを押します。

bbb.png

しばらく待まって「Installed locally」と表示されたらインストール完了です。

ccc.png

ダイアログを閉じるとプロジェクトのReferencesにabraham/twitteroauthが追加されています。

ddd.png

ツイート

index.phpを以下のように書き換えます。

index.php
<?php
require_once 'vendor/autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;

$consumerKey = 'xxxxxx';
$consumerSecret = 'xxxxxx';
$oauthToken = 'xxxxxx';
$oauthTokenSecret = 'xxxxxx';

$to = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret);
$res = $to->post('statuses/update', ['status' => 'ついーとなう']);

var_dump($res);
?>

実行してちゃんとツイートされたか確認してください。

文字化けした場合はこちらを参考にファイルの文字コードをUnicodeにします。
http://qiita.com/akabei/items/70fafaef7b86afb5a7ec

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4