How to get live tweets in c# using tweetinvi library - c#

Im using tweetinvi in c# to get stream of tweets for analysis , is there a way i can get real-Time or live filtered tweets

I am the developer of Tweetinvi. I am not sure if yoiur read the Filtered Stream documentation.
But here is how you can do what you want in few lines:
var stream = Stream.CreateFilteredStream();
// Add all your filters with AddTrack
stream.AddTrack("tweetinvi");
stream.AddTrack("rest");
stream.MatchingTweetReceived += (sender, args) =>
{
// This event will be invoked every time a tweet created is matching your criteria
var tweet = args.Tweet;
// If you want to get all the matching values
var matchingTracks = args.MatchingTracks;
var matchingFollowers = args.MatchingFollowers;
var matchingLocations = args.MatchingLocations;
// If you want to know which criteria has matched
var matchedOn = args.MatchOn;
};
stream.StartStreamMatchingAllConditions();

Related

Add older documents to stream - based on filter

I created a MongoDB watcher to create actions based on the created document.
Of course, the watcher does not detect documents that are created while the service itself is not running.
The current code is only detecting newly created documents.
How can I fetch and add older documents to the pipeline based on a field state e.g.: actionDone : true/false.
var pipeline =
new EmptyPipelineDefinition<ChangeStreamDocument<BsonDocument>>()
.Match(x => x.OperationType == ChangeStreamOperationType.Insert);
using (var cursor = collection.Watch(pipeline))
{
foreach (var change in cursor.ToEnumerable())
{
string mongoID = change.FullDocument.GetValue("_id").ToString();
}
}
Is StartAtOperationTime a option? Didnt find any good documentation here.
Update:
StartAtOperationTime was the solution I was looking for. If anybody is having the same problem, here my solution.
Start to lookup the last 10 days.
var options = new ChangeStreamOptions
{
StartAtOperationTime = new BsonTimestamp(DateTime.Now.AddDays(-10).Ticks)
};
var cursor = collection.Watch(pipeline,options)

Get element by key with Firebase in c#

I am coming to a problem where I have a guid style schema in my firebase database, which I want to display a text that is DisplayText, but for some reason my code is not working. I am using a FirebaseDatabase.Net Wrapper. How can I map it in order to read from the database properly using a guid way schema? thanks for the help.
Code:
private async Task ShowQuestion()
{
var firebase = new
FirebaseClient("https://PROJECT_URL.firebaseio.com/");
var dinos = await firebase
.Child("Questions")
.OrderByKey()
.StartAt("DisplayText")
.LimitToFirst(1)
.OnceAsync<GameController>();
foreach (var dino in dinos)
{
Console.WriteLine(dinos);
}
I tried doing:
string page = "https://PROJECT_URL.firebaseio.com/Questions/DisplayText.json?orderBy"DisplayText"&limitToFirst=1";
using (HttpClient client = new HttpClient())
using (HttpResponseMessage response = await client.GetAsync(page))
using (HttpContent content = response.Content)
{
// Reading the string.
string result = await content.ReadAsStringAsync();
Console.WriteLine(result);
// Getting a reference to the text component.
questionDisplayText = GetComponent<Text>();
questionDisplayText.text = result.ToString();
questionDisplayText.text = result.Trim(new char[] {'"'});
}
Firebase queries take a two-step approach:
You order the child nodes on their key, their value, or the value of a property.
You then filter on values of the thing you ordered on.
Since you order by key, the filtering operations like StartAt() compare the key to the value you passed. And since there is no key DisplayText, there are no results.
If you want to read the first question, you shouldn't use a startAt().
FirebaseClient("https://PROJECT_URL.firebaseio.com/");
var dinos = await firebase
.Child("Questions")
.OrderByKey()
.LimitToFirst(1)
If you want to return the results ordered by the value of their DisplayText property, it'd be something like this:
FirebaseClient("https://PROJECT_URL.firebaseio.com/");
var dinos = await firebase
.Child("Questions")
.OrderByChild("DisplayText")
.LimitToFirst(1)
Since you indicated that you want to use the REST API, here's an example of how to do that:
https://stackoverflow.firebaseio.com/59384124.json?orderBy="DisplayText"&startAt="How"
If you want to embed this string in your code, you have a few options. The main ones:
string page = "https://PROJECT_URL.firebaseio.com/Questions/DisplayText.json?orderBy=\"DisplayText\"&startAt=\"How\"&limitToFirst=1";
Or
string page = #"https://PROJECT_URL.firebaseio.com/Questions/DisplayText.json?orderBy=""DisplayText""&startAt=""How""&limitToFirst=1";
And don't forget: in order to be able to filter on the server, you'll need to define an index in your security rules. In my case I did so with:
"59384124": { ".indexOn": "DisplayText" },
Also see:
The documentation for the Firebase REST API
This blog post on embedding quotes in C# strings

Didn't getting any response while fetching Ethereum event logs data (of specific event) using Nethereum in C# console application

I am working in C# console application and need to read Ethereum event logs of specific event from Ethereum API. I have preferred Nethereum to do that task. But, Whenever i try to fetch the Event logs using API call then nothing is getting as output. Didn't get any expected data.
I have a following parameters to get event logs:
Ethereum API url
Contract ABI address
Contract address
Event name
following are the lines of code, which i am using to get event logs using Nethereum library in C# console application:
var web3 = new Nethereum.Web3.Web3(#UrlString);
var contract = web3.Eth.GetContract(#abi, #contractAddress);
var event = contract.GetEvent(#eventName);
var filter = await event.CreateFilterAsync();
var logs = await event.GetAllChanges<MultipliedEvent>(filter);
Didn't getting in "logs". Is anything missing by me?
Did you try to create a filterinput from all blocks? Like this?
var _firstBlock = BlockParameter.CreateEarliest();
var _lastBlock = BlockParameter.CreateLatest();
var web3 = new Nethereum.Web3.Web3(#UrlString);
var contract = web3.Eth.GetContract(#abi, #contractAddress);
var #event = contract.GetEvent(#eventName);
var filterInput = #event.CreateFilterInput(_firstBlock, _lastBlock);
var logs = await #event.GetAllChanges<MultipliedEvent>(filterInput);

How do I retrieve some of videos details (duration, date, views) from a playlist with YouTube API V3 in one pass

Hello SO folks and more specifically Google folks monitoring this tag per your support page. I am working from .NET and PlaylistItems.List("snippet,contentDetails") does not do a whole lot compared to the old RSS Feed search. In fact adding part contentDetails adds little value in that only the VideoID is now returned but it is already part of Snippet.ResourceId.VideoId
"kind": "youtube#playlistItem",
bla,
bla,
"contentDetails": {
"videoId": "DLME0PsJRnk"
}
Why add a "part" which is only going to return one bit of information?
How about supporting something like "snippet,contentDetails(duration,PublishedAt,Views)"
I feel this is kind of basic metadata (snippet) most apps would want to list to the users.
While you are at it please please remove this non-sense of Java casing of parameters. Why would you leak-out your language of choice into an API, that's really sad. Yes it is frustrating to keep checking whether I case-spelled them correctly.
Well, it looks like you are forcing "us" to build a list of VideoIds than turn around and make more API calls when I was doing it previously with fewer.
It also means, I will have to manage the 50 items max paging twice, once for the playlist if it is over 50 videos and then manage manually my list of VideosIds paging when I turn around to make Videos.List calls.
Let me know if I missed an All-In-One call type of API, thank you.
Here is what I have now working, let me know if there is a better way
// 20150802
public async Task<List<YouTubeInfo>> PlaylistVideosInfo(String PlaylistID)
{
var YoutubeService = YouTubeService();
//
List<YouTubeInfo> VideoInfos = new List<YouTubeInfo>();
//
var NextPageToken = "";
while (NextPageToken != null)
{
//
var SearchListRequest = YoutubeService.PlaylistItems.List("snippet");
SearchListRequest.PlaylistId = PlaylistID;
SearchListRequest.MaxResults = 50;
SearchListRequest.PageToken = NextPageToken;
// Call the search.list method to retrieve results matching the specified query term.
var SearchListResponse = await SearchListRequest.ExecuteAsync();
// Collect Video IDs from this page
var VideoIDsBatch = new List<string>(); // batch Video detail search by 50 max
foreach (var searchResult in SearchListResponse.Items)
{
VideoIDsBatch.Add(searchResult.Snippet.ResourceId.VideoId);
}
// Make API call for this batch - expect a single page :(
var VideoListRequest = YoutubeService.Videos.List("snippet,contentDetails");
VideoListRequest.Id = String.Join(",", VideoIDsBatch);
VideoListRequest.MaxResults = 50;
var VideoListResponse = await VideoListRequest.ExecuteAsync();
// Collect each Video details
foreach (var VideoResult in VideoListResponse.Items)
{
YouTubeInfoAdd(VideoInfos, VideoResult);
}
// request next page
NextPageToken = SearchListResponse.NextPageToken;
}
// Return All Videos' detail
return VideoInfos;
}

Tweetinvi Get All Tweets from a Screenname

I'm trying to use Tweetinvi to retrieve all the tweets made by a particular screen name.
I've tried GetUserTimeLine (see below) but it shows tweets from all the people I follow instead of just mine.
IUser user = Tweetinvi.User.GetUserFromScreenName("SCREEN_NAME");
// Create a parameter for queries with specific parameters
var timelineParameter = Timeline.CreateUserTimelineRequestParameter(user);
timelineParameter.ExcludeReplies = true;
timelineParameter.TrimUser = true;
timelineParameter.IncludeRTS = false;
var tweets = Timeline.GetUserTimeline(timelineParameter);
return tweets;
Thanks,
Travis
A little late, but maybe useful for others (using the Tweetinvi NuGet 0.9.12.1) :
Tweetinvi.Core.Interfaces.IUser user2 = Tweetinvi.User.GetUserFromScreenName("StackOverflow");
var userTimelineParam = new Tweetinvi.Core.Parameters.UserTimelineParameters
{
MaximumNumberOfTweetsToRetrieve = 100,
IncludeRTS=true
};
List<Tweetinvi.Core.Interfaces.ITweet> tweets2= new List<Tweetinvi.Core.Interfaces.ITweet>();
tweets2 = Timeline.GetUserTimeline(user2, userTimelineParam).ToList();
foreach (Tweetinvi.Core.Interfaces.ITweet prime2 in tweets2)
{
Debug.WriteLine(prime2.CreatedAt+" "+prime2.Text+" "+prime2.Id.ToString());
}
Twitter does not provide such endpoint. Therefore you will need to filter the tweets that have not been created by yourself.
Simply use linq (using System.Linq) to filter down the result after your code:
var tweetsPublishedByMyself = tweets.Where(x => x.Creator.Equals(user)).ToArray();

Categories