Search API Question

Nov 17, 2014 at 5:39 PM
Hello

I am making an application that will let me search for all the tweets coming from a certain country with a selected keyword.
From your example I created this

var searchParameter = Search.GenerateTweetSearchParameter("heathrow airport");
        //London coordinates
        searchParameter.SetGeoCode(Geo.GenerateCoordinates(-51.5072, 0.1275);
        searchParameter.Lang = Language.English;
        searchParameter.SearchType = SearchResultType.Popular;
        searchParameter.MaximumNumberOfResults = 100;
       var tweets = Search.SearchTweets(searchParameter);
        tweets.ForEach(t => Console.WriteLine(t.Text));
    }
However it does not seem to be returning any tweets yet.
Does anyone see a reason for this?
Nov 17, 2014 at 8:10 PM
Edited Nov 17, 2014 at 8:27 PM
Im also having trouble displaying multiple tweets I can get one tweet to return but thats it everything else gives me "Tweetinvi.Core.Interfaces.ITweet[]"
Do I need to create an array list to store the tweets before I display them?
Does anyone have an example of something similar to what I'm trying to do working?
Coordinator
Nov 18, 2014 at 1:10 PM
Edited Nov 18, 2014 at 1:11 PM
Concerning your first question.

I would guess that your restrictions are too important.
I have personally specified a 30 kilometers radius from your location and retrieved 13 tweets from the same search as yours.
searchParameter.SetGeoCode(Geo.GenerateCoordinates(-51.5072, 0.1275), 30, DistanceMeasure.Kilometers);
Have you tried to search for the keyword without specifying the location? (WORKING FOR ME)
var tweets = Search.SearchTweets("heathrow airport");
Have you tried to search for the tweets that are in this location only? (WORKING FOR ME)
// Search for all tweets published at a specific location
var searchParameter = Search.GenerateTweetSearchParameter(-51.5072, 0.1275, 30, DistanceMeasure.Kilometers);
var tweets = Search.SearchTweets(searchParameter);
Concerning your second question.

I do not understand it :s

Regards,
Linvi
Nov 18, 2014 at 10:48 PM
Hi
When I run your code "Tweetinvi.Core.Interfaces.ITweet[] is what is displayed instead of the tweets.
I don't know what this means could you explain it to me?
Coordinator
Nov 19, 2014 at 8:14 AM
Oh I see. I believe you are trying to output (Console.WriteLine) a collection instead of a single tweet.
Can you confirm that you are using the .ForEach on the tweets in order to output each of the tweets returned?
// tweets is an IEnumerable therefore printing it in the console will output the type of IEnumerable it is.
// The following line iterate over each of the tweets contained by the collection and output its text
tweets.ForEach(t => Console.WriteLine(t.Text));
Regards,
Linvi
Nov 21, 2014 at 12:53 PM
Hi

I managed to get it working thanks for your help.
Nov 23, 2014 at 8:23 PM
Hi

Would it be possible to store the keywords in an arraylist then loop through the arraylist and use the twitter process to search for each keyword in the arraylist?

This is how I imagine the process would go:
  • Create first arraylist that accepts string values
  • Create second arraylist that accepts string values
  • Create new instance of arraylist ArrayListInput”
  • Create new instance of arraylist “ArrayListOutput”
  • Functionality to clear output arraylist onClick so as not to duplicate values
  • Add relevant keywords to input arraylist, eg: Heathrow Airport, Stanstead Airport, etc.
  • For each keyword engage [Twitter process] and return keyword (string) and instance value(int)
  • Return keyword and instance value and add to output arraylist
Does this make sense and would this be possible?
Coordinator
Nov 25, 2014 at 5:21 PM
Hi,

Here is what I understand from your description:
  • You have a list of keywords that you want to search thanks to the Twitter Search API.
  • Regardless of the tweet that was searches, you want to store the result in a list.
Is that it? If yes, it is easily possible.

Linvi
Nov 25, 2014 at 6:52 PM
Hi

Yes that is exactly what i want to do
Coordinator
Nov 26, 2014 at 10:32 AM
Well what is complicated about doing this?
Nov 26, 2014 at 6:27 PM
Hi

My problem is that I've stored my keyword and the counted results in an object, but I'm having trouble returning the results in the object, right now it's just returning the object itself.

Here's my code


public class airport
{


    public long count { get; set; }
    public string airName { get; set; }
    public team(String name, long count)
    {
        this.count = count;
        this.airName = name;
    }
ArrayList AirportDiscussionInput = new ArrayList();
        AirportDiscussionInput.Add("Heathrow");
        AirportDiscussionInput.Add("Stanstead");
        AirportDiscussionInput.Add("London City Airport");


Stack myStack = new Stack();
        foreach (string keyword in AirportDiscussionInput)
        {
            var searchParameter = Search.GenerateSearchTweetParameter(keyword);
            searchParameter.Lang = Language.English;
            searchParameter.SearchType = SearchResultType.Recent;
            //searchParameter.Since = new DateTime(2014, 11, 26);            
            searchParameter.MaximumNumberOfResults = 10; 
            var tweets = Search.SearchTweets(searchParameter);
            var TweetCount = tweets.LongCount();


            Airport air = new Airport(keyword, TweetCount);

            myStack.Push(air);



            Console.WriteLine(air.airName);
            Console.WriteLine(air.count);





            string json = JsonConvert.SerializeObject(myStack);







            Firstlbl.Text = json.ToString();



        {
            object result1 = myStack.Pop();
            secondlbl.Text =result1.ToString();