本文整理匯總了PHP中Twitter::setOAuthToken方法的典型用法代碼示例。如果您正苦於以下問題:PHP Twitter::setOAuthToken方法的具體用法?PHP Twitter::setOAuthToken怎麽用?PHP Twitter::setOAuthToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Twitter
的用法示例。
在下文中一共展示了Twitter::setOAuthToken方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: loadUserByUsername
public function loadUserByUsername($username)
{
$user = $this->findUserByTwitterId($username);
if (!empty($user)) {
return $user;
}
$this->twitter_oauth->setOAuthToken($this->session->get('access_token'), $this->session->get('access_token_secret'));
try {
$info = $this->twitter_oauth->get('account/verify_credentials');
} catch (Exception $e) {
$info = null;
}
if (!empty($info)) {
if (empty($user)) {
$user = $this->userManager->createUser();
$user->setEnabled(true);
$user->setPassword('');
}
$user->setTwitterData($info);
$this->userManager->updateUser($user);
}
if (empty($user)) {
throw new UsernameNotFoundException('The user is not authenticated on twitter');
}
return $user;
}
示例2: tweet
function tweet($msg, $user)
{
global $IP;
// set up the API and post the message
$dbr = wfGetDB(DB_SLAVE);
$account = $dbr->selectRow('twitterfeedusers', array('*'), array('tfu_user' => $user->getID()));
$callback = $wgServer . '/Special:TwitterAccounts/' . urlencode($user->getName());
require_once "{$IP}/extensions/wikihow/common/twitterapi.php";
$twitter = new Twitter(WH_TWITTER_CONSUMER_KEY, WH_TWITTER_CONSUMER_SEC);
$twitter->setOAuthToken($account->tfu_token);
$twitter->setOAuthTokenSecret($account->tfu_secret);
$result = $twitter->statusesUpdate($msg);
$dbw = wfGetDB(DB_MASTER);
$dbw->insert('twitterfeedlog', array('tfl_user' => $user->getID(), 'tfl_user_text' => $user->getName(), 'tfl_message' => $msg, 'tfl_timestamp' => wfTimestampNow()));
}
示例3: activityUpdatesBySubject
public function activityUpdatesBySubject($dryrun = false)
{
echo "<h3>Running Activity Tweet Update</h3><i>Date Started: " . date('r') . "</i>" . BR . BR;
if ($dryrun == "true") {
echo "<pre>RUNNING IN DRY-RUN MODE - NO ACTUAL TWEETS WILL BE SENT!!! Remove /true in the URL to run properly!</pre>";
}
// Setup our API access
$this->load->library('twitter');
$twitter = new Twitter(array('consumerKey' => $this->consumer_key, 'consumerSecret' => $this->consumer_secret));
$twitter->setOAuthToken($this->oauth_access_token);
$twitter->setOAuthTokenSecret($this->oauth_access_secret);
// Go and get our activity information
$service_url = registry_url('services/rda/getLatestActivityBySubject/' . $this->num_days_history);
$data = @json_decode(@file_get_contents($service_url), true);
if (!isset($data['results']) || count($data['results']) == 0) {
echo "No activity information to be displayed. No updates matched the query at " . $service_url;
return;
} else {
echo "<h4>Found " . count($data['results']) . " updates for the past " . $this->num_days_history . " days...</h4>";
// Reverse the sort order so largest update counts come last (i.e. highest on the Twitter feed)
krsort($data['results']);
foreach ($data['results'] as $idx => $update) {
try {
// Format our tweet message
$tweet = sprintf("%d %s added with the subject '%s' #ANZSRC%s", $update['num_records'], pluralise("collection", $update['num_records']), ellipsis($update['value']), $update['notation']);
echo "Sending Tweet: <i>" . $tweet . "</i>...";
flush();
if (!$dryrun) {
$twitter->statusesUpdate($tweet);
echo "sent " . BR;
flush();
}
sleep(0.5);
// Pause between big chunks of tweets
if ($idx % 5 == 0) {
sleep(5);
}
} catch (TwitterException $e) {
echo BR . BR . "Unable to send Tweet to Twitter API: " . $e->getMessage() . BR . BR;
} catch (Exception $e) {
echo BR . BR . "Unknown Exception: " . $e->getMessage() . BR . BR;
}
}
}
return;
}
示例4: loadUserByUsername
public function loadUserByUsername($username)
{
$user = $this->findUserByTwitterUsername($username);
$this->twitterOauth->setOAuthToken($this->session->get('access_token'), $this->session->get('access_token_secret'));
try {
$info = $this->twitterOauth->get('account/verify_credentials');
} catch (\Exception $e) {
$info = null;
}
if (!empty($info)) {
if (isset($info->errors) && is_array($info->errors) && count($info->errors)) {
throw new AuthenticationException($info->errors[0]->message, $info->errors[0]->code);
}
if (empty($user)) {
$user = $this->userManager->createUser();
$user->setEnabled(true);
$user->setLocked(false);
}
$username = $info->screen_name;
$user->setTwitterID($info->id);
$user->setTwitterUsername($username);
$email = $user->getEmail();
if (is_null($email) || strlen(trim($email)) === 0) {
$user->setEmail($username . '@twitter.com');
}
if (null === $user->getUsername()) {
$user->setUsername($username);
}
$user->setFullName($info->name);
$this->userManager->updateUser($user);
}
if (empty($user)) {
throw new UsernameNotFoundException('The user is not authenticated on twitter');
}
return $user;
}
示例5: Twitter
<?php
// Assign these variables.
$consumerKey = '';
$consumerSecret = '';
$OAuthToken = '';
$OAuthTokenSecret = '';
$twitterOwner = '';
// Your username to receive DM notices.
define('SAFE', TRUE);
include 'lib.twitter.php';
$t = new Twitter($consumerKey, $consumerSecret);
$t->setOAuthToken($OAuthToken);
$t->setOAuthTokenSecret($OAuthTokenSecret);
$tags = '#anime #torrent';
$series = array(array('name' => 'Naruto: Shippuden', 'tags' => '#Taka', 'prefix' => '[Taka]_Naruto_Shippuuden_', 'feed' => 'http://www.nyaa.eu/?page=rss&term=naruto+shippuuden+taka+720p&filter=2'), array('name' => 'Bleach', 'tags' => '#HorribleSubs', 'prefix' => '[HorribleSubs] Bleach - ', 'feed' => 'http://www.nyaa.eu/?page=rss&term=bleach+720p&filter=2'), array('name' => 'Gintama', 'tags' => '#HorribleSubs #MKV', 'prefix' => '[HorribleSubs] Gintama - ', 'feed' => 'http://www.nyaa.eu/?page=rss&term=Gintama+720p+HorribleSubs&filter=2'), array('name' => 'Gosick', 'tags' => '#HatsuyukiTsuki #MKV', 'prefix' => '[Hatsuyuki-Tsuki]_Gosick_-_', 'feed' => 'http://www.nyaa.eu/?page=rss&term=Gosick+Hatsuyuki-Tsuki+720&filter=2'));
header('Content-Type: text/plain');
$new = 0;
foreach ($series as $anime) {
$feed = file_get_contents($anime['feed']);
if (!$feed) {
continue;
}
$feed = simplexml_load_string($feed);
$seriesTweeted = false;
foreach ($feed->channel->item as $release) {
if (substr($release->title, 0, strlen($anime['prefix'])) == $anime['prefix']) {
$episode = substr($release->title, strlen($anime['prefix']));
@preg_match('/[0-9]{1,4}/', $episode, $episode);
if (!isset($episode[0]) || !strlen($episode[0])) {
continue;
示例6: wfNotifyTwitter
function wfNotifyTwitter($cat, $t)
{
global $wgUser, $IP;
if (!$cat) {
return true;
}
try {
$dbr = wfGetDB(DB_SLAVE);
// special case for rising star
$account = $dbr->selectRow(array('twitterfeedaccounts', 'twitterfeedcatgories'), array('*'), array('tfc_username=tws_username', 'tfc_category' => $cat->getDBkey()));
// anything to check?
if (!$account) {
return true;
}
$msg = TwitterAccounts::getUpdateMessage($t);
// did we already do this?
$count = $dbr->selectField('twitterfeedlog', '*', array('tfl_user' => $wgUser->getID(), 'tfl_message' => $msg, 'tfl_twitteraccount' => $account->tws_username));
if ($count > 0) {
return true;
}
// set up the API and post the message
$callback = $wgServer . '/Special:TwitterAccounts/' . urlencode($account->tws_username);
require_once "{$IP}/extensions/wikihow/common/twitterapi.php";
$twitter = new Twitter(WH_TWITTER_CONSUMER_KEY, WH_TWITTER_CONSUMER_SEC);
$twitter->setOAuthToken($account->tws_token);
$twitter->setOAuthTokenSecret($account->tws_secret);
#print_r($twitter); print_r($account); exit;
$result = $twitter->statusesUpdate($msg);
#print_r($result); echo $msg; exit;
// log it so we have a paper trail
$dbw = wfGetDB(DB_MASTER);
$dbw->insert('twitterfeedlog', array('tfl_user' => $wgUser->getID(), 'tfl_user_text' => $wgUser->getName(), 'tfl_message' => $msg, 'tfl_twitteraccount' => $account->tws_username, 'tfl_timestamp' => wfTimestampNow()));
} catch (Exception $e) {
#print_r($e); exit;
}
return true;
}
示例7: Twitter
require_once 'twitter.php';
/*
APPLICATION LEVEL DETAILS
Create new Twitter class instance with our 'consumer key' and 'consumer secret'
Find this on your Twitter app page. Example: http://screencast.com/t/a5s93L91V
*/
$twitter = new Twitter('2jSDrs6wyzxVyPKn4ex3LQ', 'vVXyzrcwPFDAQ8fxrgjgfkZ274QejvadOHKUp3MyNS0');
/*
USER LEVEL DETAILS
Uncomment the first chunk below ("GET TOKEN / SECRET") to find out this information
*/
$token = "252211321-1twXTQ78LW0WmynHQQN50WTP9yecDyixSWlm1N3v";
$secret = "V7vQD4X873ELJP2Oeje9fbCcB71jTPtY7m6jtJhg";
//$userId = "252211321";
//$screenName = "upennClassDemo";
$twitter->setOAuthToken($token);
$twitter->setOAuthTokenSecret($secret);
?>
<br/><br/>
<a href='/classes/viewSource/?path=<?php
echo $_SERVER['PHP_SELF'];
?>
' target='_blank'>View Source</a><br/><br/><br/>
<a href='http://classes.verkoyen.eu/modules/twitter_oauth/files/php_twitter_2_0_3.zip'>Download twitter.php (wrapper library)</a><br/><br/>
<?php
/*-------------------------------------------------------------------------------------------------
GET USER TIMELINE
-------------------------------------------------------------------------------------------------*/
echo "<h2>User Timeline (upennClassDemos)</h2>";
示例8: tags2array
}
$w3 = array();
$w3["question"] = $frageid;
$w3["tag"] = $a;
$db->CreateUpdate(0, "question_tags", $w3);
}
$_SESSION["myuser"]["lastwritten"]["question"][$frageid] = true;
Karma::RuleAction("CREATE_QUESTION", array("user" => MyUser::id(), "question" => $frageid));
Badges::add(3, MyUser::id(), array("question" => $frageid));
//Erste Frage geschrieben
@file_get_contents("www.google.com/webmasters/tools/ping?sitemap=" . urlencode(SiteConfig::val("baseurl") . "sitemap.xml"));
$m = SiteConfig::get(0);
if ($m["twitter"]["consumer"]["secret"] . "" != "" && $m["twitter"]["access"]["secret"] . "" != "") {
try {
$twitter = new Twitter($m["twitter"]["consumer"]["key"], $m["twitter"]["consumer"]["secret"]);
$twitter->setOAuthToken($m["twitter"]["access"]["key"]);
$twitter->setOAuthTokenSecret($m["twitter"]["access"]["secret"]);
$url = API_urlshortener::add(Question::PermalinkByData($w3["question"], $w["title"]));
if (strlen($w["title"]) > 100) {
$tweet = substr($w["title"], 0, 100) . "... " . $url . " #wikihelp";
} else {
$tweet = substr($w["title"], 0, 100) . " " . $url . " #wikihelp";
}
$twitter->statusesUpdate($tweet);
} catch (Exception $ex) {
}
}
header("Location: " . Question::PermalinkByData($frageid));
}
}
function tags2array($text)
示例9: list
function _send($token, $secret, $row)
{
require_lang('twitter');
require_code('twitter');
list($message) = render_activity($row, false);
$link = static_evaluate_tempcode(pagelink_to_tempcode($row['a_pagelink_1']));
// Shorten message for Twitter purposes
$chopped_message = html_entity_decode(strip_tags($message->evaluate()), ENT_COMPAT, get_charset());
$max_length = 255;
$shortened_link = mixed();
if ($link != '') {
$shortened_link = http_download_file('http://is.gd/api.php?longurl=' . urlencode($link));
$max_length -= strlen($shortened_link) + 1;
}
if (strlen($chopped_message) > $max_length) {
$chopped_message = substr($chopped_message, 0, $max_length - 3) . '...';
}
if ($link != '') {
$chopped_message .= ' ' . $shortened_link;
}
require_code('character_sets');
$chopped_message = convert_to_internal_encoding($chopped_message, get_charset(), 'utf-8');
require_code('developer_tools');
destrictify();
// Initiate Twitter connection
$api_key = get_option('twitter_api_key');
$api_secret = get_option('twitter_api_secret');
$twitter = new Twitter($api_key, $api_secret);
$twitter->setOAuthToken($token);
$twitter->setOAuthTokenSecret($secret);
// Send message
try {
$twitter->statusesUpdate($chopped_message);
} catch (TwitterException $e) {
attach_message($e->getMessage(), 'warn');
return false;
}
return true;
}
示例10: getCallback
public function getCallback()
{
$token = Input::get('oauth_token');
$verifier = Input::get('oauth_verifier');
$accessToken = Twitter::oAuthAccessToken($token, $verifier);
if (isset($accessToken['user_id'])) {
$user_id = $accessToken['user_id'];
$user = User::find($user_id);
if (empty($user)) {
$user = new User();
$user->id = $user_id;
}
Twitter::setOAuthToken($accessToken['oauth_token']);
Twitter::setOAuthTokenSecret($accessToken['oauth_token_secret']);
$timeline = Twitter::statusesUserTimeline($user->id);
$user->screen_name = $accessToken['screen_name'];
$user->profile_image_url = $timeline[0]['user']['profile_image_url'];
$user->oauth_token = $accessToken['oauth_token'];
$user->oauth_token_secret = $accessToken['oauth_token_secret'];
$user->save();
Auth::login($user);
return Redirect::to('/');
exit;
} else {
return Redirect::to('login')->with('message', 'Twitter認証できませんでした。');
exit;
}
}
示例11: delete_retweet
/**
* Delete the Tweet
*/
public function delete_retweet()
{
if (!empty($this->config['consumer_key']) && !empty($this->params['id'])) {
// create instance
$twitter = new Twitter($this->config['consumer_key'], $this->config['consumer_secret']);
// set tokens
$twitter->setOAuthToken($this->config['oauth_token']);
$twitter->setOAuthTokenSecret($this->config['oauth_token_secret']);
$twitter->statusesDestroy($this->params['id']);
}
expHistory::back();
}
示例12: renewserver
function renewserver($server, $cmd = false)
{
$settings = getsettings();
if ($settings['usegrowl']['config'] == 'yes') {
require_once 'lib/growl/class.growl.php';
$growlip = $settings['growlip']['config'];
$growlpass = $settings['growlpass']['config'];
}
if ($settings['usetwitter']['config'] == 'yes') {
require_once 'lib/twitter/twitter.php';
$consumerkey = $settings['consumerkey']['config'];
$consumersecret = $settings['consumersecret']['config'];
$OAuthToken = $settings['OAuthToken']['config'];
$OAuthTokenSecret = $settings['OAuthTokenSecret']['config'];
$twitter = new Twitter("{$consumerkey}", "{$consumersecret}");
$twitter->setOAuthToken("{$OAuthToken}");
$twitter->setOAuthTokenSecret("{$OAuthTokenSecret}");
}
if ($settings['useboxcar']['config'] == 'yes') {
require_once 'lib/boxcar/boxcar_api.php';
$boxemail = $settings['boxemail']['config'];
}
$gametypes = gametypes();
if ($server == "all") {
$server = '%';
}
//if (!$cmd == 'true') { $game = $_GET[ 'game' ];}
//else { $game = '%'; }
$fails = array();
$result = mysql_query_trace("SELECT * from servers where serverid like '{$server}' and type like '" . $_GET['game'] . "'") or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
foreach ($row as $key => $value) {
${$key} = $value;
}
$info = "";
$serverIP = $ip;
$server = new SourceServer($serverIP, $port);
try {
$info = $server->getServerInfo();
$rules = $server->getRules();
print $rules['sv_registration_succesful'];
} catch (Exception $e) {
// $fails[] = $serverid;
// no longer needed, since we just want it to continue
}
if ($info && $info['serverName']) {
$network = $info['networkVersion'];
$version = $info['gameVersion'];
$servername = trim($info['serverName']);
$type = $info['gameDir'];
$os = $info['operatingSystem'];
$map = $info['mapName'];
$pwpro = $info['passwordProtected'];
$nplayers = $info['numberOfPlayers'];
$mplayers = $info['maxPlayers'];
$bots = $info['botNumber'];
$protected = $info['passwordProtected'];
$servertags = $info['serverTags'];
if ($replaymatch == "yes") {
try {
$server->rconAuth($rconpass);
$matchid = $server->rconExec('steamworks_sessionid_server');
} catch (Exception $e) {
echo $e;
}
$pattern = '([0-9][0-9][0-9]+)';
preg_match($pattern, $matchid, $matches);
if ($matches[0]) {
mysql_query_trace("INSERT INTO matchids ( serverid, mapname, sessionid ) VALUES( '{$serverid}','{$map}','{$matches['0']}' )");
}
}
if ($retries > "9") {
if ($settings['useemail']['config'] == 'yes') {
$subject = "{$servername} seems to be back up after it was down for {$retries}, which is in minutes";
$message = "Like the topic says, {$servername} seems to be back up after it was down for {$retries}";
$smtpmails = $settings['emailalert']['config'];
$allmails = explode(",", $smtpmails);
foreach ($allmails as $sendto) {
mail($sendto, $subject, $message, null);
}
}
if ($settings['usegrowl']['config'] == 'yes') {
$growl = new Growl();
//$growl->setAddress($growlip, $growlpass);
$connection = array('address' => '$growlip', 'password' => '$growlpass');
$growl->notify($connection, "{$type}", "RESTORED: {$servername}", "Instance {$servername} was down for {$retries} minutes. It is now back up again");
}
if ($settings['usetwitter']['config'] == 'yes') {
try {
$twitter->statusesUpdate("RESTORED: {$servername}. It was down for {$retries} minutes.");
} catch (Exception $e) {
echo $e;
}
}
if ($settings['useboxcar']['config'] == 'yes') {
include "config.php";
$b = new boxcar_api($boxcarapi, $boxcarsec);
$emails = explode(",", $boxemail);
foreach ($emails as $boxalert) {
try {
//.........這裏部分代碼省略.........
示例13: fire
public function fire($job, $data)
{
$post_id = $data['post_id'];
$post = Post::find($post_id);
if (!empty($post)) {
$user_id = $post->user_id;
$post_url = '';
preg_match_all('#[-a-zA-Z0-9@:%_\\+.~\\#?&//=]{2,256}\\.[a-z]{2,4}\\b(\\/[-a-zA-Z0-9@:%_\\+.~\\#?&//=]*)?#si', $post->content, $url_matches);
if (!empty($url_matches)) {
$all_urls = $url_matches[0];
$post_url = !empty($all_urls[0]) ? $all_urls[0] : '';
}
$network_ids = PostNetwork::where('post_id', '=', $post_id)->lists('network_id');
$network = Network::where('user_id', '=', $user_id)->select('user_token', 'user_secret', 'network')->whereIn('id', $network_ids)->get();
$client = new GuzzleHttp\Client();
if (!empty($network)) {
foreach ($network as $s) {
if ($s->network == 'twitter') {
try {
Twitter::setOAuthToken($s->user_token);
Twitter::setOAuthTokenSecret($s->user_secret);
$twitter_response = Twitter::statusesUpdate($post->content);
} catch (Exception $e) {
}
} else {
if ($s->network == 'linkedin') {
if (!empty($post_url)) {
try {
$post_data = array('comment' => $post->content, 'content' => array('description' => $post->content), 'visibility' => array('code' => 'anyone'));
$post_data['content']['submittedUrl'] = $post_url;
$request_body = $post_data;
$linkedin_resource = '/v1/people/~/shares';
$request_format = 'json';
$linkedin_params = array('oauth2_access_token' => $s->user_token, 'format' => $request_format);
$linkedinurl_info = parse_url('https://api.linkedin.com' . $linkedin_resource);
if (isset($linkedinurl_info['query'])) {
$query = parse_str($linkedinurl_info['query']);
$linkedin_params = array_merge($linkedin_params, $query);
}
$request_url = 'https://api.linkedin.com' . $linkedinurl_info['path'] . '?' . http_build_query($linkedin_params);
$request_body = json_encode($request_body);
$linkedin_response = CurlRequester::requestCURL('POST', $request_url, $request_body, $request_format);
} catch (Exception $e) {
}
}
} else {
if ($s->network == 'facebook') {
try {
$post_data = array('access_token' => $s->user_token, 'message' => $post->content);
if (!empty($post_url)) {
$post_data['link'] = $post_url;
}
$res = $client->post('https://graph.facebook.com/me/feed', array('query' => $post_data));
$response_body = $res->getBody();
$response_body = json_decode($response_body, true);
} catch (Exception $e) {
}
}
}
}
}
}
}
$post->published = 1;
$post->save();
$job->delete();
}
示例14: get_twitter_class
/**
* holds an instance of the Twitter Connect Class
* @return Twitter Class
*/
private static function get_twitter_class()
{
if (!self::$twitter_class) {
$member = Member::currentUser();
if ($member && $member->TwitterID) {
require_once dirname(dirname(dirname(__FILE__))) . '/thirdparty/twitter/Twitter.php';
require_once dirname(dirname(dirname(__FILE__))) . '/thirdparty/twitter/Exception.php';
self::$twitter_class = new TijsVerkoyen\Twitter\Twitter(self::$consumer_key, self::$consumer_secret);
if ($member->TwitterToken && $member->TwitterSecret) {
self::$twitter_class->setOAuthToken($member->TwitterToken);
self::$twitter_class->setOAuthTokenSecret($member->TwitterSecret);
}
}
}
return self::$twitter_class;
}