本文整理汇总了PHP中Abraham\TwitterOAuth\TwitterOAuth::get方法的典型用法代码示例。如果您正苦于以下问题:PHP TwitterOAuth::get方法的具体用法?PHP TwitterOAuth::get怎么用?PHP TwitterOAuth::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Abraham\TwitterOAuth\TwitterOAuth
的用法示例。
在下文中一共展示了TwitterOAuth::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public function create()
{
DB::transaction(function () {
$twitterClient = new TwitterOAuth(Config::get('services.twitter.consumerKey'), Config::get('services.twitter.consumerSecret'), Config::get('services.twitter.accessToken'), Config::get('services.twitter.accessSecret'));
// Fetch the tweet information from Twitter, if a tweet id was passed through (it is possible the tweet was created manually without an id)
if (array_key_exists('tweet_id', $this->input)) {
$tweet = $twitterClient->get('statuses/show', ['id' => $this->input['tweet_id']]);
$tweetOwner = $tweet->user;
$this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Tweet, 'tweet_text' => $tweet->text, 'tweet_id' => $tweet->id, 'tweet_parent_id' => $tweet->in_reply_to_status_id, 'size' => strlen($tweet->text), 'title' => $tweet->text, 'summary' => $this->input['summary'], 'cryptographic_hash' => hash('sha256', $tweet->text), 'originated_at' => Carbon::createFromFormat('D M d H:i:s P Y', $tweet->created_at)->toDateTimeString(), 'status' => ObjectPublicationStatus::QueuedStatus]);
} else {
$this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Tweet, 'tweet_text' => $this->input['tweet_text'], 'size' => strlen($this->input['tweet_text']), 'title' => $this->input['tweet_text'], 'summary' => $this->input['summary'], 'cryptographic_hash' => hash('sha256', $this->input['tweet_text']), 'originated_at' => $this->input['originated_at'], 'status' => ObjectPublicationStatus::QueuedStatus]);
}
try {
if (!isset($tweetOwner)) {
$tweetOwner = $twitterClient->get('users/show', ['screen_name' => $this->input['tweet_screen_name']]);
}
$tweeter = Tweeter::byScreenName($tweetOwner->screen_name)->firstOrFail();
} catch (ModelNotFoundException $e) {
$tweeter = Tweeter::create(['screen_name' => $tweetOwner->screen_name, 'user_name' => $tweetOwner->name, 'description' => $tweetOwner->description]);
$tweeter->saveProfilePicture();
}
$this->object->tweeter()->associate($tweeter);
$this->createMissionRelation();
$this->createTagRelations();
$this->object->push();
});
return $this->object;
}
示例2: getTweets
function getTweets($notification)
{
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$date = $notification['date'];
$keywords = array("sirene", "gevaar", "ongeluk", "ambulance", "ziekenwagen", "ongeval", "gewond", "letsel", "brand", "vlam", "vuur", "brandweer", "blus", "water", "overval", "politie", "dief", "wapen", "letsel", "inbraak", "schiet", "misdrijf");
$start_date = "since:" . date(DATE_FORMAT, $date);
$end_date = "until:" . date(DATE_FORMAT, strtotime("+1 day", $date));
//$search_string = $notification['town'] . " " . implode(" OR ", $keywords) . " -p2000 " . $start_date . " " . $end_date;
$search_string = implode(" OR ", KEYWORDS_GEN) . " -p2000 -RT " . $start_date . " " . $end_date;
$cur_min = min(100, $notification["num_tweets"]);
$params = array('q' => $search_string, 'lang' => 'nl', 'count' => $cur_min);
//$statuses = json_encode((array)$twitter->get("search/tweets", $params));
$temp = (array) $twitter->get("search/tweets", $params);
$statuses = $temp["statuses"];
$total_num = count($statuses);
$num_stat = count($statuses);
$min_id = $statuses[$num_stat - 1]->id;
while ($total_num < $notification["num_tweets"] && $num_stat >= $cur_min) {
$cur_min = min($notification["num_tweets"] - $total_num, 100);
$params = array('q' => $search_string, 'lang' => 'nl', 'count' => $cur_min, 'max_id' => $min_id);
$new_temp = (array) $twitter->get("search/tweets", $params);
$new_stat = $new_temp["statuses"];
$num_stat = count($new_stat);
$total_num = $total_num + $num_stat;
$min_id = $new_stat[$num_stat - 1]->id;
$statuses = array_merge($statuses, $new_stat);
}
//What do I do with the statuses?
return json_encode($statuses);
}
示例3: checkCredentials
/**
* {@inheritdoc}
*/
public function checkCredentials()
{
$application = $this->twitterOauth->get('account/verify_credentials');
if (isset($application->errors)) {
throw new BadAuthenticationException(sprintf('An error occurred during the authentication : %s', implode(', ', $this->parseErrors($application->errors))));
}
return true;
}
示例4: index
/**
* Show the application dashboard.
*
* @return Response
*/
public function index()
{
$access_token = getenv('TWITTER_ACCESS_TOKEN');
$access_token_secret = getenv('TWITTER_ACCESS_TOKEN_SECRET');
$consumer_key = getenv('TWITTER_CONSUMER_KEY');
$consumer_secret = getenv('TWITTER_CONSUMER_SECRET');
$connection = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret);
$content = $connection->get("account/verify_credentials");
$statuses = $connection->get("statuses/home_timeline", array("count" => 25, "exclude_replies" => true));
error_log(print_r($statuses, true));
return view('mytweets', ['mytweets' => $statuses]);
}
示例5: search
function search($string, $count, $type)
{
$access_token = "3227234898-oMKzM9SSY9aE5I4viIisGZ58mQJceIPn6KhCiS9";
$access_token_secret = "xHN3fYrkGAiNgSowvxigh1mMLXfegDtozP04f0s1ODRT1";
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret);
$content = $connection->get("account/verify_credentials");
// var_dump($content);
$statuses = $connection->get("search/tweets", array("lang" => "pt", "q" => $string, "count" => "20", "result_type" => $type));
// var_dump($statuses);
// echo '<pre>'; print_r($statuses); echo '</pre>';
return $statuses;
}
示例6: getConnection
/**
* @return TwitterOAuth
*/
protected function getConnection()
{
if ($this->connection === null) {
$config = Di::getDefault()->getConfig()->get('twitter');
$this->connection = new TwitterOAuth($config['apiKey'], $config['apiSecret'], $config['accessToken'], $config['accessTokenSecret']);
$content = $this->connection->get("account/verify_credentials");
if (isset($content->errors)) {
var_dump($content->errors);
die;
}
}
return $this->connection;
}
示例7: getLastTweets
/**
* return the (xà last tweet(s) for an screenname
*
* @param $username
* @param $count
* @param bool $replies
* @param bool $rts
* @return array
*/
public function getLastTweets($username, $count, $replies = false, $rts = false)
{
$tweets = $this->twitter->get('statuses/user_timeline', ['screen_name' => $username, 'exclude_replies' => !$replies, 'include_rts' => $rts, 'count' => $count]);
$response = [];
foreach ($tweets as $tweet) {
$t = new Tweet();
$t->setText($tweet->text);
$t->setSource($tweet->source);
$t->setName($tweet->user->name);
$t->setScreen($tweet->user->screen_name);
$t->setDate($tweet->created_at);
$response[] = $t;
}
return $response;
}
示例8: getPosts
public function getPosts()
{
//接続情報
$connection = new TwitterOAuth($this->consumerKey, $this->consumerSecret, $this->accessToken, $this->accessTokenSecret);
$content = $connection->get("search/tweets", ["geocode" => $this->location, "result_type" => "recent"]);
return $content;
}
示例9: setLogin
public static function setLogin($token, $isadmin = false, $db)
{
$_auth['tw_token'] = $token;
$twitter = new TwitterOAuth(tw_consumer_key, tw_consumer_secret, $token['oauth_token'], $token['oauth_token_secret']);
$response = $twitter->get('account/verify_credentials');
$user = array('id' => $response->id, 'name' => $response->name, 'screen_name' => $response->screen_name, 'location' => $response->location, 'time_zone' => $response->time_zone, 'verified' => $response->verified, 'profile_image_url' => $response->profile_image_url, 'lang' => $response->lang);
$_auth['user'] = $user;
$_auth['isadmin'] = $user['id'] === 83455478;
// $_auth['twitter']=$twitter;
$sth = $db->prepare('INSERT INTO login
(
twitter_id,
twitter_name,
twitter_screen_name,
twitter_location,
twitter_time_zone,
twitter_lang
)
VALUES
(
:twitter_id,
:twitter_name,
:twitter_screen_name,
:twitter_location,
:twitter_time_zone,
:twitter_lang
)');
$sth->execute(array(':twitter_id' => $user['id'], ':twitter_name' => $user['name'], ':twitter_screen_name' => $user['screen_name'], ':twitter_location' => $user['location'], ':twitter_time_zone' => $user['time_zone'], ':twitter_lang' => $user['lang']));
$_auth['login_id'] = $db->lastInsertId();
session::set('auth', $_auth);
}
示例10: perform_request
/**
* Performs a request using the TwitterOAuth library
* @see https://twitteroauth.com/
* @param $action - what to retrieve from the Twitter REST API (e.g. trends/place )
* @param $params - parameters to be passed during the Twitter API request
*/
function perform_request($action, $params){
$connection = new TwitterOAuth(TwitterConfig::$consumerKey, TwitterConfig::$consumerSecret, TwitterConfig::$accessToken, TwitterConfig::$accessTokenSecret);
$response = $connection->get($action, $params);
echo json_encode($response);
}
示例11: getLongLat
public function getLongLat($query)
{
$GEOdatax = "";
$GEOdata = "";
if ($query != NULL) {
$consumer = "3Hsr7qk9HEYseF9bpJA07Go6H";
$consumersecret = "q1TjkWCHcPKrJn0YCmtKMwIHaXURI7ip3z5eDxDd4G0GxLsUOi";
$accesstoken = "3803581341-FAlmx3CbE2amgcMyD2AkGYuLdRa7kZ3QcDSxj5a";
$accesstokensecret = "1JtROKIjMaIhP6IJGMPGbTyRTF9WMyq1RGclpdvcKzZWD";
$twitter = new TwitterOAuth($consumer, $consumersecret, $accesstoken, $accesstokensecret);
$url = "geo/search";
$GEOquery = $twitter->get($url, array('query' => $query, 'granularity' => 'city', 'max_results' => '1'));
foreach ($GEOquery->result->places as $GEOresult) {
$GEOdata = $GEOresult->centroid;
$GEOtype = $GEOresult->place_type;
}
if ($GEOdata != NULL) {
$GEOdatax = implode(',', $GEOdata);
if ($GEOtype == "country") {
$radius = ',479km';
} else {
$radius = ',35mi';
}
$GEOdatax = $GEOdatax . $radius;
}
}
return $GEOdatax;
}
示例12: testLastResult
public function testLastResult()
{
$this->twitter->get('search/tweets', array('q' => 'twitter'));
$this->assertEquals('search/tweets', $this->twitter->getLastApiPath());
$this->assertEquals(200, $this->twitter->getLastHttpCode());
$this->assertObjectHasAttribute('statuses', $this->twitter->getLastBody());
}
示例13: actionIndex
/**
* This is the default 'index' action that is invoked
* when an action is not explicitly requested by users.
*/
public function actionIndex()
{
// get all places from db
$places = Place::model()->findAll();
// *** twitter api *** //
//twitter authentication
$connection = new TwitterOAuth("8gpWBVBSfGB2clOm8thLz29yu", "KkSJTv5chO4e6AzGsOkctKnk8nnFjdHzXzISDLM48AZ91gneGG", "3299182320-gipHvZakrdUnQIzfLVP4D5i4uP34vxfqSabxHny", "7D93mzbvVxwujnH20vYbuCPM8LRpZ1vfhCq4LEW5bwGrA");
$content = $connection->get("account/verify_credentials");
// search tweets
$tweets = $connection->get("search/tweets", array("q" => "chiangmai"));
// *** end twitter api *** //
// weather api
$weather = json_decode(file_get_contents("http://api.openweathermap.org/data/2.5/weather?q=chiangmai&units=metric"));
// render index page and pass places, tweets, and weather
$this->render('index', array('places' => $places, 'tweets' => $tweets, 'weather' => $weather));
}
示例14: actionTweets
public function actionTweets()
{
$postData = Yii::$app->getRequest()->getBodyParams();
if (isset($postData['latitude']) && $postData['latitude'] && isset($postData['longitude']) && $postData['longitude']) {
$data = Yii::$app->cache->get($postData['city']);
if ($data === false) {
// $data is expired or is not found in the cache
$geocode = $postData['latitude'] . ',' . $postData['longitude'] . ',' . self::SEARCH_RADIUS;
$connection = new TwitterOAuth('wT8o4IrBGCCNcnHxZfobEvHVV', 'eG3GQ7nqMXzO14IK7whGd1SyQmWqrKKRfgJJXmeqp910ryA3NV', '2376724225-0m1tu3Q8ru20mTyA0zjxGFKxRBEQkBTaTCAszQl', 'FEuuyd15giBingpwBgpIlQ0T419cUKcAA4kPJF6QLmiNb');
$tweets = $connection->get("search/tweets", array("geocode" => $geocode));
$result = [];
foreach ($tweets->statuses as $tweet) {
//check tweet with geo exist
if (isset($tweet->geo) && is_array($tweet->geo->coordinates) && count($tweet->geo->coordinates) > 0) {
$result[] = array('desc' => $tweet->text, 'avatar' => $tweet->user->profile_image_url, 'created_at' => $tweet->created_at, 'lat' => $tweet->geo->coordinates[0], 'long' => $tweet->geo->coordinates[1]);
}
}
$this->insertTweets($postData['city'], $result);
Yii::$app->cache->set($postData['city'], $result, self::CACHE_TIME);
return ['success' => true, 'result' => $result];
} else {
return ['success' => true, 'result' => $data];
}
}
return ['success' => false, 'result' => []];
}
示例15: getFeed
/**
* get user's twitter feed
*
* @return array|bool
*/
public function getFeed()
{
$oFeed = $this->_oTwitterOAth->get("statuses/home_timeline", ["count" => 25, "exclude_replies" => true]);
if ($this->_oTwitterOAth->getLastHttpCode() === 200) {
return $oFeed;
}
return false;
}