Trending Topic

Oct 21, 2013 at 5:54 PM
Hello :

There is a way to get the trending topic Tweetinvi i have been looking in the documentation but i have not found this function.

Regards.
Víctor.
Oct 21, 2013 at 6:33 PM
Hi Victor,

If you are talking about this Place Trends, this is currently not available through Tweetinvi.
As a consequence you will need to create the method yourself but don't be scared this is very easy :)

To simplify your life I've done some of the work for you :)
private static List<string> GetTrendsFromPlaceId(int placeId, IToken token)
{
    List<string> trends = null;

    ObjectResponseDelegate trendAction = placeTrends =>
    {
        Console.WriteLine(placeTrends);
        var trendObjects = placeTrends.GetProp<object[]>("trends").Cast<Dictionary<string, object>>();
        trends = trendObjects.Select(x => x.GetProp<string>("name")).ToList();
    };

    var url = String.Format("https://api.twitter.com/1.1/trends/place.json?id={0}", placeId);
    token.ExecuteGETQuery(url, trendAction);

    return trends;
}
Tell me if this helps or if you need more help :)

Regards,
Linvi
Marked as answer by linvi on 10/29/2013 at 4:45 AM
Oct 21, 2013 at 7:26 PM
Hello :

Thanks a lot for your help, it is exactly what i have been looking for.
I will test and give feedback.

One more question?? There is a way in this library i can get where is the source the user tweet for example the user twett from iphone, ipad or web for make stat.??

Regards.
Víctor
Oct 21, 2013 at 8:18 PM
I don't think you can get this information from any Library as I don't know any field provided by Twitter that gives this information.
You can see all the information you can get from a tweet here.

Linvi
Oct 26, 2013 at 11:07 AM
Thanks for the above code. I was trying to get some help for the Trend Places on Twitter. ok. I have a quick query. How to get the place id? Is is some drop down that I will fill for the places? If so, How to get the places ?
Oct 26, 2013 at 5:06 PM
Hi there,

Most of the Twitter API related with locations has not been implemented and detecting the place_id has also not been done.
You will have to read the documentation of the twitter API here :
The queries are pretty simple and I believe you can construct them yourself using the Token.ExecuteGetQuery as shown above.
ObjectResponseDelegate placeAction = place =>
{
    // Do something when receiving a place
};
var url = String.Format("MY_QUERY_URL");
token.ExecuteGETQuery(url, placeAction);
I do not have time to provide you a concrete example but I believe this should not be difficult.
Please let me know whether you succeeded.

Kind Regards,
Linvi
Oct 26, 2013 at 5:39 PM
Edited Oct 26, 2013 at 5:55 PM
@linvi: I am new this technology. You are requested to kindly provide some sample code to fetch places.

Thanks and Regards
Pankaj
Oct 26, 2013 at 6:15 PM
Will it be possible for you to check in the code and provide it in Codeplex. This will help a lot in future for everybody.

Thanks and Regards
Pankaj Garg
Oct 26, 2013 at 8:06 PM
Hi,

I will send you some code sample when I'll have time to do this. I will try my best to send it within 3 days.

Kind regards,
Linvi
Oct 28, 2013 at 12:18 AM
Hi Pankaj,

I would be happy to help you but I need to know which of the featured I listed you are interested in.
Trends and Places are 2 topics that will be developed after the 0.9.0.0 release that will be a huge update.
This update will result in an important refactoring and I am not willing to add features before this update.

As a result I would like to know precisely which feature you need and limit it as much as possible as I will not implement the entire PlaceSearch API in Tweetinvi before the associated release.

Kind Regards,
Linvi
Nov 13, 2014 at 5:03 PM
Edited Nov 13, 2014 at 5:05 PM
Hi -

Thank you for posting this. A few weeks ago I was using a modified version of the above code and all was working fine. I now seem to be getting the following error on the ExecuteGETQuery() function call "The request was aborted: Could not create SSL/TLS secure channel." I've included the code below and unfortunately haven't been able to find a solution. Would you mind suggesting any workarounds?

Thank you for your help
int placeId = 23424977;
            var url = String.Format("https://api.twitter.com/1.1/trends/place.json?id={0}", placeId);
            
            
            ObjectResponseDelegate trendAction = placeTrends =>
            {
                var trendObjects = placeTrends.Where(a => a.Key == "trends");
                var trendWrapper = trendObjects.First().Value;

                var trends = (object[])trendWrapper;
                List<string> hashTags = new List<string>();

                foreach (var t in trends)
                {
                    var trend = ((Dictionary<string, object>)t).First().Value.ToString();
                    if (trend.Contains("#"))
                    {
                        if (!hashTags.Contains(trend))
                        {
                            hashTags.Add(trend);
                        }
                    }
                }

                var result = _Flow.SaveTrendingHashtags(hashTags);
                if (result.success)
                {
                    LogMessage("Trending hashtags: Successfully saved " + result.totalSaved + " trending hashtags", result.eventType);
                }
                else {
                    LogMessage("Trending hashtags: Error " + result.exception, result.eventType);
                }
              
            };

            token.ExecuteGETQuery(url, trendAction);
The token variable is instantiated as follows
var cred = TwitterCredentials.CredentialsAccessor.CurrentThreadCredentials;
         IToken token  token = new Token(cred.AccessToken, cred.AccessTokenSecret, cred.ConsumerKey, cred.ConsumerSecret);
Nov 17, 2014 at 11:48 AM
The version you are using is very old, please update your code to the latest version.
I have checked and the following code is working in 0.9.4.x:
// Get PlaceTrends from Tweetinvi
int placeId = 23424977;
var placeTrends = Trends.GetTrendsAt(placeId);

// Get From Query
int placeId = 23424977;
var url = String.Format("https://api.twitter.com/1.1/trends/place.json?id={0}", placeId);
var result = TwitterAccessor.ExecuteGETQuery<IPlaceTrends[]>(url).First();
Linvi