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();
Related
Since a few days I have been using Youtube's (Google's) API 3.0 (.NET Google API Library)
Everything was going smooth until I stumbled across a problem. I've tried many methods to figure out why I got a low amount of info from my results.
What I am trying in the code down below, is requesting the first comment on a video.
Then with that first comment (CommentThread), I am trying to retrieve all the replies of users that reacted on this comment.
I have tried getting information before, it works fine. I could loadup the entire comment section. Except for more than 5 replies per CommentThread. (CommentThread is basicly a comment under a video, where some have replies.)
This is my code, I have modified it alot of times, but from the looks of it. This one should work.
private static void searchReplies()
{
int count = 0;
YouTubeService youtube = new YouTubeService(new BaseClientService.Initializer() { ApiKey = Youtube.API.KEY });
List<string[]> comments = new List<string[]>();
var commentThreadsListRequest = youtube.CommentThreads.List("snippet,replies");
commentThreadsListRequest.VideoId = Youtube.Video.ID;
commentThreadsListRequest.Order = CommentThreadsResource.ListRequest.OrderEnum.Relevance;
commentThreadsListRequest.MaxResults = 1;
var commentThreadsListResult = commentThreadsListRequest.Execute();
foreach (var CommentThread in commentThreadsListResult.Items)
{
var commentListRequest = youtube.Comments.List("snippet");
commentListRequest.Id = CommentThread.Id;
var commentListResult = commentListRequest.Execute();
foreach (var Item in commentListResult.Items)
{
CommentThreadIDs.Add(Item.Id);
}
MessageBox.Show("COUNT:" + CommentThread.Replies.Comments.Count);
foreach (var Reply in CommentThread.Replies.Comments)
{
CommentThreadIDs.Add(Reply.Id);
}
}
}
I have checked my API and the video ID. They are all fine as I can request alot of other information.
I have tested this with several videos, but all videos where the first comment have more than 5 replies, it fails to get them all.
The result (Message Box with "Count:") I get (the amount of replies I get in CommentThread.Replies.Comments is 5. No matter what I do. Going to next page with a token does not work either as it is empty.
Does anyone know why it only returns 5 comments instead of more?
I found the answer with help of someone.
The problem was that I set the ID of a commentThread to a comment ID.
Instead I have to set the commentThread ID to the parent ID.
The following code fully replaces my old code if anyone ever needs it.
YouTubeService yts = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "12345" });
var commentThreadsListRequest = yts.CommentThreads.List("snippet,replies");
commentThreadsListRequest.VideoId = "uywOqrvxsUo";
commentThreadsListRequest.Order = CommentThreadsResource.ListRequest.OrderEnum.Relevance;
commentThreadsListRequest.MaxResults = 1;
var commentThreadResult = commentThreadsListRequest.Execute().Items.First();
var commentListRequest = yts.Comments.List("snippet");
commentListRequest.Id = commentThreadResult.Id;
commentListRequest.MaxResults = 100;
var commentListResult = commentListRequest.Execute();
var comments = commentListResult.Items.Select(x => x.Snippet.TextOriginal).ToList();
I'm trying to make a targetingIdeaService API call to Google AdWords. This is my code so far:
[HttpGet]
public IEnumerable<string> Get()
{
var user = new AdWordsUser();
using (TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(AdWordsService.v201802.TargetingIdeaService))
{
// Create selector.
TargetingIdeaSelector selector = new TargetingIdeaSelector();
selector.requestType = RequestType.IDEAS;
selector.ideaType = IdeaType.KEYWORD;
selector.requestedAttributeTypes = new AttributeType[] {
AttributeType.KEYWORD_TEXT,
AttributeType.SEARCH_VOLUME,
AttributeType.AVERAGE_CPC,
AttributeType.COMPETITION,
AttributeType.CATEGORY_PRODUCTS_AND_SERVICES
};
// Set selector paging (required for targeting idea service).
var paging = Paging.Default;
// Create related to query search parameter.
var relatedToQuerySearchParameter =
new RelatedToQuerySearchParameter
{ queries = new String[] { "bakery", "pastries", "birthday cake" } };
var searchParameters = new List<SearchParameter> { relatedToQuerySearchParameter };
var page = new TargetingIdeaPage();
page = targetingIdeaService.get(selector);
return new string[] { "value1", "value2" };
}
}
it looks ok, compiles at last, and so on. But then I went into debug mode. And I saw this:
So as you can see, the variable doesn't have the access token. The other data comes from app.config file.
I am quite certain the keys passed in are correct.
Then the code throws the famous invalid_grand error. In my case, I believe that's because the access token is not being generated. I'm new to AdWords and ASP.NET, so I probably missed something, but I have no idea what.
I used the
docs,
Code Structure instructions, and
code examples to put it all together.
I had my configuration wrong. I had to recreate all the credentials using incognito window. If you have any issues just open a thread here: https://groups.google.com/forum/#!forum/adwords-api
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();
Using System.DirectoryServices, one can get the highestCommittedUSN this way:
using(DirectoryEntry entry = new DirectoryEntry("LDAP://servername:636/RootDSE"))
{
var usn = entry.Properties["highestCommittedUSN"].Value;
}
However, I need to get this information from a remote ADLDS using System.DirectoryServices.Protocols, which does not leverage ADSI. Following is a simplified code sample of what I'm attempting to do:
using(LdapConnection connection = GetWin32LdapConnection())
{
var filter = "(&(highestCommittedUSN=*))";
var searchRequest = new SearchRequest("RootDSE", filter, SearchScope.Subtree, "highestCommittedUSN");
var response = connection.SendRequest(searchRequest) as SearchResponse;
var usn = response.Entries[0].Attributes["highestCommittedUSN"][0];
}
Unfortunately this kicks back a "DirectoryOperationException: The distinguished name contains invalid syntax." At first I thought there might be something wrong in GetWin32LdapConnection() but that code is called in numerous other places to connect to the directory and never errors out.
Any ideas?
Thanks for the idea, Zilog. Apparently to connect to the RootDSE, you have to specify null for the root container. I also switched the filter to objectClass=* and the search scope to "base." Now it works!
using(LdapConnection connection = GetWin32LdapConnection())
{
var filter = "(&(objectClass=*))";
var searchRequest = new SearchRequest(null, filter, SearchScope.Base, "highestCommittedUSN");
var response = connection.SendRequest(searchRequest) as SearchResponse;
var usn = response.Entries[0].Attributes["highestcommittedusn"][0];
}
I hope this saves someone else some time in the future.
I want to fetch books using Amazon Product Advertising API with asp.net and C#. All the guides and codes are so confusing as to they don't give you a single method to search the books.
Is there any single stub that can be used to call the service and fetch the books based on the ISBN.
thanks
There's a good sample solution you can download.
http://aws.amazon.com/code/2480?_encoding=UTF8&queryArg=searchQuery&x=0&fromSearch=1&y=0&searchPath=code&searchQuery=Advertising
They give you a class called SignedRequestHelper, then you make a call like this:
public static void Main()
{
SignedRequestHelper helper = new SignedRequestHelper(MY_AWS_ACCESS_KEY_ID, MY_AWS_SECRET_KEY, DESTINATION);
/*
* The helper supports two forms of requests - dictionary form and query string form.
*/
String requestUrl;
String title;
/*
* Here is an ItemLookup example where the request is stored as a dictionary.
*/
IDictionary<string, string> r1 = new Dictionary<string, String>();
r1["Service"] = "AWSECommerceService";
r1["Version"] = "2009-03-31";
r1["Operation"] = "ItemLookup";
r1["ItemId"] = ITEM_ID;
r1["ResponseGroup"] = "Small";
/* Random params for testing */
r1["AnUrl"] = "http://www.amazon.com/books";
r1["AnEmailAddress"] = "foobar#nowhere.com";
r1["AUnicodeString"] = "αβγδεٵٶٷٸٹٺチャーハン叉焼";
r1["Latin1Chars"] = "ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJij";
requestUrl = helper.Sign(r1);
title = FetchTitle(requestUrl);
System.Console.WriteLine("Method 1: ItemLookup Dictionary form.");
System.Console.WriteLine("Title is \"" + title + "\"");
System.Console.WriteLine();
}
You need to use the ItemLookup (like the example) but set the IdType to ISBN. Then set the ItemId to the actual ISBN. Here are the details on ItemLookup:
docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?ItemLookup.html
I get this when I use that sample. looks like there has been a change in the API recently.
System.InvalidOperationException: There is an error in the XML document. ---> Sy
stem.InvalidOperationException: <ItemLookupResponse xmlns='http://webservices.am
azon.com/AWSECommerceService/2011-08-01'> was not expected.
To fetch books install this library (Install-Package Nager.AmazonProductAdvertising)
https://www.nuget.org/packages/Nager.AmazonProductAdvertising/
Example:
var authentication = new AmazonAuthentication("accesskey", "secretkey");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.UK);
var result = await client.GetItemsAsync("978-0261102385");