/*
Add user's tweets to provided user object.
8762
private static Tweets addTweets(User user, String body, Date tweetDate, String tweetId)
    {
        Tweets tweet = new Tweets();
        tweet.setTweetId(tweetId);
        tweet.setBody(body);
        tweet.setTweetDate(tweetDate);
        user.getTweets().add(tweet);
        return tweet;
    }
1042176
public static function fromArray(array $retweet): self
    {
        $extendedEntities = isset($retweet['extended_entities'])
            ? $retweet['extended_entities']
            : null
        ;
        $user = isset($retweet['user'])
            ? User::fromArray($retweet['user'])
            : null
        ;
        
        return new self(
            $retweet['id'],
            $retweet['text'],
            $retweet['lang'],
            $retweet['created_at'],
            $retweet['geo'],
            $retweet['coordinates'],
            $retweet['place'],
            $retweet['retweet_count'],
            $retweet['favorite_count'],
            $retweet['entities'],
            $extendedEntities,
            $user
        );
    }
147719
function render(tweet) {
    var html = '<li><div class="tweet">';
    html += '<div class="vcard"><a href="http://twitter.com/' + tweet.user.screen_name + '" class="url"><img style="height: 48px; width: 48px;" alt="' + tweet.user.name + '" class="photo fn" height="48" src="' + tweet.user.profile_image_url + '" width="48" /></a></div>';
    html += '<div class="hentry"><strong><a href="http://twitter.com/';
    html += tweet.user.screen_name + '" ';
    html += 'title="' + tweet.user.name + '">' + tweet.user.screen_name + '</a></strong> ';
    html += '<span class="entry-content">';
    html += twitterlib.ify.clean(tweet.text); //twitterlib.expandLinks(tweet));
    html += '</span> <span class="meta entry-meta"><a href="http://twitter.com/' + tweet.user.screen_name;
    html += '/status/' + tweet.id_str + '" class="entry-date" rel="bookmark"><span class="published" title="';
    html += twitterlib.time.datetime(tweet.created_at) + '">' + twitterlib.time.relative(tweet.created_at) + '</span></a>';
    if (tweet.source) html += ' <span>from ' + tweet.source + '</span>';
    if (tweet.retweetedby) html += ' <span>retweeted by ' + tweet.retweetedby.screen_name + '</span>';
    html += '</span></div></div></li>';

    return html;
  }
656403
protected function addTwitter()
	{
		// Get value for title tag
		$title = $this->renderTitle();

		// Get value of description
		$description = ($this->description) ? $this->description : $this->getConfig('description');

		// Get Default values in config file
		$image = $this->getConfig('twitter.image');
		$site = $this->getConfig('twitter.site');
		$creator = $this->getConfig('twitter.creator');

		// Check if option is active
		if ($this->getConfig('twitter.active'))
		{
			// Register default tag but don't override a value set manually
			if (!array_key_exists('twitter:card', $this->meta['name']))
			{
				$this->addOneMeta('name', 'twitter:card', 'summary');
			}

			// Don't override a value set manually
			if (!array_key_exists('twitter:title', $this->meta['name']))
			{
				$this->addOneMeta('name', 'twitter:title', $title);
			}

			// Don't override a value set manually
			if (!array_key_exists('twitter:description', $this->meta['name']))
			{
				$this->addOneMeta('name', 'twitter:description', $description);
			}

			// Don't override a value set manually + check if file exists
			if (File::isFile(public_path($image)) && !array_key_exists('twitter:image:src', $this->meta['name']))
			{
				$this->addOneMeta('name', 'twitter:image:src', $image);
			}

			// Don't override a value set manually
			if (!array_key_exists('twitter:site', $this->meta['name']))
			{
				$this->addOneMeta('name', 'twitter:site', $site);
			}

			// Don't override a value set manually
			if (!array_key_exists('twitter:creator', $this->meta['name']))
			{
				$this->addOneMeta('name', 'twitter:creator', $creator);
			}

			// Don't override a value set manually
			if (!array_key_exists('twitter:url', $this->meta['name']))
			{
				$this->addOneMeta('name', 'twitter:url', URL::current());
			}
		}

		// Option is inactive
		else
		{
			$this->killTwitter();
		}
	}
504141
def addUsersToGroup(self, user_ids, thread_id=None):
        
        thread_id, thread_type = self._getThread(thread_id, None)
        data = self._getSendData(thread_id=thread_id, thread_type=ThreadType.GROUP)

        data["action_type"] = "ma-type:log-message"
        data["log_message_type"] = "log:subscribe"

        user_ids = require_list(user_ids)

        for i, user_id in enumerate(user_ids):
            if user_id == self._uid:
                raise FBchatUserError(
                    "Error when adding users: Cannot add self to group thread"
                )
            else:
                data[
                    "log_message_data[added_participants][{}]".format(i)
                ] = "fbid:{}".format(user_id)

        return self._doSendRequest(data)
350016
public static void main(String[] args) {
        try {
            Twitter twitter = new TwitterFactory().getInstance();
            int page = 1;
            List<User> users;
            do {
                users = twitter.getBlocksList(page);
                for (User user : users) {
                    System.out.println("@" + user.getScreenName());
                }
                page++;
                // this code ends up in an infinite loop due to the issue 1988
                // http://code.google.com/p/twitter-api/issues/detail?id=1988
            } while (users.size() > 0 && page <= 10);
            System.out.println("done.");
            System.exit(0);
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to get blocking users: " + te.getMessage());
            System.exit(-1);
        }
    }
1059173
public static void main(String[] args) {
        if (args.length < 3) {
            System.out.println(
                    "Usage: java twitter4j.examples.user.UpdateFriendship [screen name] [enable device notification(true|false)] [enable retweets(true|false)]");
            System.exit(-1);
        }
        try {
            Twitter twitter = new TwitterFactory().getInstance();
            Relationship relationship = twitter.updateFriendship(args[0]
                    , Boolean.parseBoolean(args[1]), Boolean.parseBoolean(args[2]));
            System.out.println("Successfully updated the friendship of [" + relationship.getTargetUserScreenName() + "].");
            System.exit(0);
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to update the friendship: " + te.getMessage());
            System.exit(-1);
        }
    }
416774
public static void main(String[] args) {
        try {
            Twitter twitter = new TwitterFactory().getInstance();
            List<Status> statuses = twitter.getFavorites();
            for (Status status : statuses) {
                System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
            }
            System.out.println("done.");
            System.exit(0);
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to get favorites: " + te.getMessage());
            System.exit(-1);
        }
    }
469284
@Override
    public void getUserSuggestions(final String categorySlug) {
        getDispatcher().invokeLater(new AsyncTask(USER_SUGGESTIONS, listeners) {
            @Override
            public void invoke(List<TwitterListener> listeners) throws TwitterException {
                ResponseList<User> users = twitter.getUserSuggestions(categorySlug);
                for (TwitterListener listener : listeners) {
                    try {
                        listener.gotUserSuggestions(users);
                    } catch (Exception e) {
                        logger.warn("Exception at getUserSuggestions", e);
                    }
                }
            }
        });
    }
352866
def swap_twitter_subject(subject, body):
    """"""

    if subject.startswith('Tweet from'):
        lines = body.split('\n')
        for idx, line in enumerate(lines):
            if re.match(r'.*, ?\d{2}:\d{2}]]', line) is not None:
                try:
                    subject = lines[idx + 1]
                except IndexError:
                    pass
                break
    return subject, body
229088
def urlize_tweet(tweet):
    
    text = tweet.get('html', tweet['text'])
    for hash in tweet['entities']['hashtags']:
        text = text.replace('#%s' % hash['text'], TWITTER_HASHTAG_URL % (quote(hash['text'].encode("utf-8")), hash['text']))
    for mention in tweet['entities']['user_mentions']:
        text = text.replace('@%s' % mention['screen_name'], TWITTER_USERNAME_URL % (quote(mention['screen_name']), mention['screen_name']))
    tweet['html'] = text
    return tweet
638568
def publish(self, user, provider, obj, comment, **kwargs):
        '''
            
        '''
        social_user = self._get_social_user(user, provider)
        backend = self.get_backend(social_user, provider, context=kwargs)
        return backend.publish(obj, comment)
719422
def user_timeline(request):
    """"""
    user = request.user.twitterprofile
    twitter = Twython(settings.TWITTER_KEY, settings.TWITTER_SECRET,
                      user.oauth_token, user.oauth_secret)
    user_tweets = twitter.get_home_timeline()
    return render_to_response('tweets.html', {'tweets': user_tweets})
796632
async def AddUser(self, users):
        '''
        
        '''
        # map input types to rpc msg
        _params = dict()
        msg = dict(type='UserManager',
                   request='AddUser',
                   version=2,
                   params=_params)
        _params['users'] = users
        reply = await self.rpc(msg)
        return reply
580337
public static void main(String[] args) {
        try {
            Twitter twitter = new TwitterFactory().getInstance();
            System.out.println("Showing suggested user categories.");
            ResponseList<Category> categories = twitter.getSuggestedUserCategories();
            for (Category category : categories) {
                System.out.println(category.getName() + ":" + category.getSlug());
            }
            System.out.println("done.");
            System.exit(0);
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to get suggested categories: " + te.getMessage());
            System.exit(-1);
        }
    }
461831
def tweets_for_user(screen_name, limit=1e10):
    
    qu = Queue()
    p = Thread(target=_tweets_for_user, args=(qu, screen_name, limit))
    p.start()
    p.join(910)
    if p.is_alive():
        sys.stderr.write('no results after 15 minutes for %s. Aborting.' % screen_name)
        return []
    else:
        return qu.get()
235118
protected function createTweet(\stdClass $tweetTmp, $user, $inTimeline)
    {
        $tweet = new Tweet();

        $tweet
            ->setId($tweetTmp->id)
            ->setValues($tweetTmp)
            ->setUser($user)
            ->setInTimeline($inTimeline);

        $this->addMedias($tweetTmp, $tweet);

        return $tweet;
    }