Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Sep 07, 2015 @ 13:50
    Ismail Mayat
    0

    Hashtag mention count

    Anders,

    I am going to try and do

    twitterService.Search.GetTweets("#umbraco", 100);
    

    Then using that get count of tweets which would be hash tag mention count. However just noticed your docs

    "The maximum limit for this method seems to be 100. Nothing will go wrong if you specify a higher limit - the API will just not respond with more than 100 tweets per page."

    Is there a different way of doing this to get what i need which is actual no of times that hash tag is mentioned.

    Regards

    Ismail

  • Anders Bjerner 487 posts 2989 karma points MVP 8x admin c-trib
    Sep 07, 2015 @ 15:58
    Anders Bjerner
    100

    Unfortunately I haven't come across anything in the API that works similar to what you're doing with Instagram.

    At best you can use pagination to go beyond the first 100 tweets:

    // Declare the initial options
    TwitterSearchTweetOptions options = new TwitterSearchTweetOptions {
        Query = "#umbraco",
        Count = 50,
        ResultType = TwitterSearchTweetResultType.Recent
    };
    
    // Get the first page of tweets
    TwitterSearchTweetsResponse response = service.Search.GetTweets(options);
    
    // Loop through the tweets
    foreach (TwitterStatusMessage tweet in response.Body.Statuses) {
        <pre>@tweet.Id: @tweet.Text</pre>
    }
    
    <hr />
    
    // Update the options
    options.MaxId = response.Body.Statuses.Last().Id - 1;
    
    // Get the next page of tweets
    response = service.Search.GetTweets(options);
    
    // Loop through the tweets
    foreach (TwitterStatusMessage tweet in response.Body.Statuses) {
        <pre>@tweet.Id: @tweet.Text</pre>
    }
    

    But Twitter writes the following in their API documentation:

    Please note that Twitter’s search service and, by extension, the Search API is not meant to be an exhaustive source of Tweets. Not all Tweets will be indexed or made available via the search interface.

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Sep 08, 2015 @ 08:37
    Ismail Mayat
    0

    Anders,

    Excellent many thanks for that I now have:

    var twitterService = _skybrudClientFactory.SkyBrudTwitterService;
            bool doQuery = true;
            int hashTagCount = 0;
            // Declare the initial options
            var options = new TwitterSearchTweetOptions
            {
                Query = "#umbraco",
                Count = 100,
                IncludeEntities=false,
                ResultType = TwitterSearchTweetResultType.Mixed
            };
    
            while (doQuery)
            {
                TwitterSearchTweetsResponse response = twitterService.Search.GetTweets(options);
                if (response.Response.StatusCode == HttpStatusCode.OK && response.Body.Statuses != null && response.Body.Statuses.Any())
                {
                    hashTagCount += response.Body.Statuses.Count();
                    options.MaxId = response.Body.Statuses.Last().Id - 1; //get next batch as we have limit to 100
    
                }
                else
                {
                    doQuery = false;
                }                
            }
    

    Any suggestions improvements to code welcome ;-} I am including entities as I am not bothered I just want statuses with that hash tag, unless replies or re tweets would be ignored?

    Regards

    Ismail

  • Anders Bjerner 487 posts 2989 karma points MVP 8x admin c-trib
    Sep 09, 2015 @ 09:47
    Anders Bjerner
    0

    I haven't tested your code, but it seems to be correct ;)

Please Sign in or register to post replies

Write your reply to:

Draft