Skip to content

Instantly share code, notes, and snippets.

@nissuk
Created May 31, 2010 15:08
Show Gist options
  • Save nissuk/419916 to your computer and use it in GitHub Desktop.
Save nissuk/419916 to your computer and use it in GitHub Desktop.
Services_TwitterとServices_Bitlyでtweetする例
<?php
// tweet test
require_once 'HTTP/OAuth/Consumer.php';
require_once 'Services/Twitter.php';
require_once 'Services/Bitly.php';
// http://dev.twitter.com/apps/{数字} 内の「Consumer key」
$consumer_key = '';
// http://dev.twitter.com/apps/{数字} 内の 「Consumer secret」
$consumer_secret = '';
// http://dev.twitter.com/apps/{数字}/my_token 内の 「Access Token (oauth_token)」
$auth_token = '';
// http://dev.twitter.com/apps/{数字}/my_token 内の 「Access Token Secret (oauth_token_secret)」
$token_secret = '';
// bit.lyのアカウント名
$bitly_login = '';
// http://bit.ly/a/account 内の「API Key」
$bitly_apikey = '';
$bitly = new Services_Bitly($bitly_login, $bitly_apikey);
$status = "test (by Services_Twitter: {$bitly->shorten('http://d.hatena.ne.jp/shimooka/20100527/1274941968')}, Services_Bitly: {$bitly->shorten('http://openpear.org/package/Services_Bitly')})";
try {
$twitter = new Services_Twitter();
$oauth = new HTTP_OAuth_Consumer(
$consumer_key,
$consumer_secret,
$auth_token,
$token_secret
);
$twitter->setOAuth($oauth);
$msg = $twitter->statuses->update($status);
print_r($msg);
} catch (Services_Twitter_Exception $e) {
echo $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment