当前位置: 首页>>代码示例>>PHP>>正文


PHP TwitterAPIExchange::setGetField方法代码示例

本文整理汇总了PHP中TwitterAPIExchange::setGetField方法的典型用法代码示例。如果您正苦于以下问题:PHP TwitterAPIExchange::setGetField方法的具体用法?PHP TwitterAPIExchange::setGetField怎么用?PHP TwitterAPIExchange::setGetField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TwitterAPIExchange的用法示例。


在下文中一共展示了TwitterAPIExchange::setGetField方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: InsertTweetById

 static function InsertTweetById($data, $settings, $marathon, $campaign, $database)
 {
     $id;
     $error = false;
     $errorMessage;
     $output;
     if (array_key_exists('Id', $data)) {
         $id = $data['Id'];
     } else {
         if (array_key_exists(0, $data)) {
             $id = $data[0];
         } else {
             $error = true;
             $errorMessage = 'No id was provided.';
         }
     }
     if ($database instanceof ZdpArrayObject) {
         $error = true;
         $errorMessage = $database['error'];
     }
     if (!$error || true) {
         $url = 'https://api.twitter.com/1.1/statuses/show.json';
         $fields = '?id=' . $id . '&include_my_retweet=0';
         $method = 'GET';
         $twitter = new TwitterAPIExchange(['oauth_access_token' => $settings['troauthpub'], 'oauth_access_token_secret' => $settings['troauthsec'], 'consumer_key' => $settings['trpub'], 'consumer_secret' => $settings['trsec']]);
         $tweet = json_decode($twitter->setGetField($fields)->buildOauth($url, $method)->performRequest());
         $sql = 'CALL sp_insert_twitterevent (:campaign_id, :twitter_user, :tweet_content, :tweet_date, :marathon_id, :campaign_id)';
         $statement = $database->prepare($sql);
         //Attempts to process the insert statement of the Twitter event.
         if ($statement->execute([':campaign_id' => 1, ':twitter_user' => $tweet->user->screen_name, ':tweet_content' => $tweet->text, ':tweet_date' => strtotime($tweet->created_at), ':marathon_id' => $marathon, ':campaign_id' => $campaign])) {
             $output = new ZdpArrayObject(['result' => new ZdpArrayObject(['id' => $tweet->id_str])]);
         } else {
             $output = new ZdpArrayObject(['error' => $statement->errorInfo()]);
         }
     } else {
         $output = new ZdpArrayObject(['error' => $errorMessage]);
     }
     return $output;
 }
开发者ID:noahshrader,项目名称:zdp,代码行数:39,代码来源:Events.class.php

示例2: array

/*
by Aldo Ginting
*/
require_once 'TwitterAPIExchange.php';
/* tokens */
$settings = array('oauth_access_token' => '102024246-fPvUBae3FMD1Ab4zQDxzi7SUSvOYPpkZnbaWGNHE', 'oauth_access_token_secret' => 'aBYuCbiItkU99caHK8S4mIzbUBnx8YSB7IP4HrbRpjYTg', 'consumer_key' => 'Sgym1Ov9J4opgdB7gNtQHC0tP', 'consumer_secret' => '5icBNUmq3GcWhT7seMzD34SLMBhAXbCDMBQiOBe4sqZ9gEiXrw');
// user timeline request settings
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$requestmethod = 'GET';
$getField = '?screen_name=aldogint&count=5';
// instance TwitterAPIExchange
$twitterAPIExchange = new TwitterAPIExchange($settings);
// throw request
// then decode json to associative array
$response = json_decode($twitterAPIExchange->setGetField($getField)->buildOauth($url, $requestmethod)->performRequest(), $assoc = true);
// check for error
if (isset($response["errors"])) {
    echo "<h3>Oops, we encountered a problem.</h3><p>Here's error message:</p><p><em>" . $response["errors"][0]["message"] . "</em></p>";
    exit;
}
// echo "<pre>";
// echo var_dump($response) . "</pre>";
// display
foreach ($response as $items) {
    echo "<hr>";
    echo $items['user']['name'] . " (@" . $items['user']['screen_name'] . ") - " . $items['created_at'];
    echo "<br>" . screenNameAsLink(convertLink($items['text']));
    echo "<hr>";
}
// functions
开发者ID:aldogint,项目名称:SistemInformasiTerdistribusi,代码行数:30,代码来源:getUserTL.php

示例3: fwrite

while ($cursor != 0) {
    $i++;
    //Get the first 5,000 followers, use the cursor to step through
    $getfield = '?screen_name=' . $twUser . '&cursor=' . $cursor;
    $followers_json = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
    $followers_decoded = json_decode($followers_json);
    fwrite($handle, "FETCHING MORE LOOP NUMBER :  " . $i . ' | ' . $cursor . "\n");
    //the lookup.json method can only handle a max of 100 at a time
    $to_look_up = array_chunk($followers_decoded->ids, 100);
    foreach ($to_look_up as &$ids) {
        //nothing dupes, skip to the next 100
        if (count($ids) == 0) {
            continue;
        }
        //hydrate the remaining ids
        $apiResp = $twitter->setGetField('?user_id=' . implode(',', $ids))->buildOauth('https://api.twitter.com/1.1/users/lookup.json', $requestMethod)->performRequest();
        $users_list = json_decode($apiResp);
        set_time_limit(30);
        foreach ($users_list as $key => $user) {
            if (filter_var($user->profile_image_url, FILTER_VALIDATE_URL) !== false) {
                //download the image
                $filename = explode('/', $user->profile_image_url);
                $filename = end($filename);
                $filename = str_replace('_normal.', '_bigger.', $filename);
                $ext = explode('.', $filename);
                $ext = end($ext);
                $success = file_put_contents('images/' . $user->screen_name . '.' . $user->id . '.' . $ext, file_get_contents(str_replace('_normal.', '_bigger.', $user->profile_image_url)));
                $write = $user->id . " :: " . $user->screen_name . " :: " . $success . "\n";
                fwrite($handle, $write);
            } else {
                $write = $user->id . " :: " . $user->screen_name . " :: " . $user->profile_image_url . " :: " . 'NO URL FOR IMAGE' . "\n";
开发者ID:palamago,项目名称:tw-images,代码行数:31,代码来源:app.php

示例4: array

<?php

require_once 'TwitterAPIExchange.php';
require_once 'Geocode.php';
/** Set access tokens **/
$settings = array('oauth_access_token' => "363822513-CPj3YUXqvSiUjd6819PRqGmafXKiNVXyG6R69j3j", 'oauth_access_token_secret' => "8u3Iwa24EsoxynyJrsklgOOx0GJbNYrcnWe9lXIZviwiy", 'consumer_key' => "O6ltnFO2colJblrbNRewDPfNq", 'consumer_secret' => "QKFj889PAgPKoHbUUUTzd5lCFqHCknudBRsTu0JPBQPSB5rCaO");
$url = "https://api.twitter.com/1.1/search/tweets.json";
$requestMethod = "GET";
/*$since_id = "471479529731411968";
$max_id = "697189541694873600";*/
$getfield = '?q=%23#flintwatercrisis&src=tyah&result_type=recent&count=100';
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetField($getfield)->buildOauth($url, $requestMethod)->performRequest(), $assoc = TRUE);
if (file_exists('coordinates.json')) {
    $saved_coords = json_decode(file_get_contents('coordinates.json'), true);
} else {
    $saved_coords['flint'] = array('lat' => 43.01, 'long' => 83.69);
}
$count = 0;
foreach ($string["statuses"] as $statuses) {
    $count++;
    $location = strtolower($statuses['user']['location']);
    //check to see if we already have that location OR get it.
    if ($location && !array_key_exists($location, $saved_coords)) {
        $coordinates = geocode($location);
        $saved_coords[$location] = array('lat' => $coordinates['lat'], 'long' => $coordinates['long']);
    }
    $id = $statuses['id'];
    echo "Tweet_ID: " . $id . "<br />";
    //convert date to mysql datetime format
    $twitter_date = $statuses['created_at'];
开发者ID:mjbradburn,项目名称:flint-water-tweet-tracker,代码行数:31,代码来源:index.php


注:本文中的TwitterAPIExchange::setGetField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。