Ejemplo n.º 1
0
 public GenerateController(
     ApplicationDbContext db,
     TwitterApiClient twitter,
     ChatworkApiClient chatwork
     )
 {
     this.db       = db;
     this.twitter  = twitter;
     this.chatwork = chatwork;
 }
        static void Main(string[] args)
        {
            Console.Write("Write hashtags words, separated with ',' and without '#' char:");
            List <string> keywords = Console.ReadLine().Split(',').ToList();

            Console.Write("Write languages for tweets, separated with ',' (ex. en, es):");
            List <string> languages = Console.ReadLine().Split(',').ToList();

            Console.Write(
                "Write pairs of coordinates for tweets located from the inbox(es) created, separated with ',' (ex. -122.75,36.8,-121.75,37.8 for tweets from San Francisco):");
            List <string> boxCoordinates = Console.ReadLine().Split(',').ToList();

            while (boxCoordinates.Count % 4 != 0)
            {
                Console.Write(
                    "Non multiple of 4 number of coordinates detected, please add a pair number of coordinates (or none for avoid) (ex. -122.75,36.8,-121.75,37.8 for tweets from San Francisco):");
                boxCoordinates = Console.ReadLine().Split(',').ToList();
            }

            List <MapBoxCoordinates> mapBoxCoordinates = new List <MapBoxCoordinates>();

            for (int i = 0; i < boxCoordinates.Count; i = i + 4)
            {
                mapBoxCoordinates.Add(
                    new MapBoxCoordinates(decimal.Parse(boxCoordinates[i].Replace('.', ',')),
                                          decimal.Parse(boxCoordinates[i + 1].Replace('.', ',')),
                                          decimal.Parse(boxCoordinates[i + 2].Replace('.', ',')),
                                          decimal.Parse(boxCoordinates[i + 3].Replace('.', ','))));
            }

            TwitterApiClient twitterApiClient =
                new TwitterApiClient(new HTTP.Helpers.HttpInvoker());

            twitterApiClient.SetCredentials(""
                                            , ""
                                            , ""
                                            , "");

            twitterApiClient.StartStreamingTweets("dummykey", keywords, languages,
                                                  mapBoxCoordinates, (object sender, TweetStreamArgs e) =>
            {
                if (e.Tweet != null)
                {
                    Console.WriteLine(e.Tweet.text);
                    Console.WriteLine();
                }
            });

            Console.ReadKey();
        }
Ejemplo n.º 3
0
        public HttpResponseMessage GetTwitter()
        {
            try
            {
                string jsonString = TwitterApiClient.GetUserTimelineJson(StateManager.TwitterBearerToken, "tooksnet", 20, true);

                if (string.IsNullOrWhiteSpace(jsonString))
                {
                    return(Request.CreateResponse(HttpStatusCode.NoContent));
                }

                return(Request.CreateResponse(HttpStatusCode.OK, jsonString));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Ejemplo n.º 4
0
        } = "BBC";                                              // default


        public static List <TwitterFeedModel> GetTwitterFeeds(string inConsumerKey, string inConsumerSecret, string inTwitterUsername = "******")
        {
            TwitterApiClient = SetTokenBaseData();

            // Post token body content
            var content        = new FormUrlEncodedContent(SetContentValues());
            var requestMessage = SetPostContent(content, Base64EncodedAuthenticationString(inConsumerKey, inConsumerSecret));

            // Make the request
            var response = TwitterApiClient.SendAsync(requestMessage).Result;

            response.EnsureSuccessStatusCode();
            string responseBody = response.Content.ReadAsStringAsync().Result;

            // Get Tweets
            var accessToken = GrabTokenInString(responseBody);
            var twitterFeed = GetTweets(inTwitterUsername, accessToken);

            return(twitterFeed);
        }
        public static void Register(HttpConfiguration config)
        {
            // Configuración y servicios de API web
            var container = new UnityContainer();

            container.RegisterType <IHttpInvoker, HttpInvoker>(
                new ContainerControlledLifetimeManager());

            container.RegisterType <ITwitterApiClient, TwitterApiClient>(
                new ContainerControlledLifetimeManager(),
                new InjectionFactory(c =>
            {
                IHttpInvoker httpInvoker  = container.Resolve <IHttpInvoker>();
                TwitterApiClient instance = new TwitterApiClient(httpInvoker);
                instance.SetCredentials("jkuG56zlta1exJJ3kGi2mlXRM"
                                        , "kPHXBkmLqOV9thDnFE4QJpvzND7hkJBp8AYtwcIts9l64LEmt8"
                                        , "430727651-vHPtvToq1UK3RHm3tMrQmQA4BW3PdJlxAopL53We"
                                        , "rEArJ1vb8Uuh24WTeh9tW8DKFPNWfEvEFte3jdfUkXaPC");
                return(instance);
            }));

            RequiresAuthorizationFilter authorizationFilter =
                new RequiresAuthorizationFilter(WebSocketController.ClientsConnections);

            container.RegisterInstance(typeof(RequiresAuthorizationFilter), authorizationFilter);

            config.DependencyResolver = new UnityResolver(container);

            config.Filters.Add(authorizationFilter);

            // Rutas de API web
            config.MapHttpAttributeRoutes();

            //config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate:
            //    "api/{controller}/{id}", defaults: new { id =
            //    RouteParameter.Optional }
            //);
        }
Ejemplo n.º 6
0
        private static List <TwitterFeedModel> GetTweets(string inTwitterUserName, string inToken)
        {
            var requestUserTimeline = new HttpRequestMessage(HttpMethod.Get, string.Format(
                                                                 $"https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={inTwitterUserName}&count=9"
                                                                 ));

            requestUserTimeline.Headers.Add("Authorization", "Bearer " + inToken);
            var    responseUserTimeLine = TwitterApiClient.SendAsync(requestUserTimeline).Result;
            string responseTwitter      = responseUserTimeLine.Content.ReadAsStringAsync().Result;

            // Fetch Json Result
            if (responseUserTimeLine.IsSuccessStatusCode)
            {
                var twitterFeeds = JsonConvert.DeserializeObject <List <TwitterFeedModel> >(responseTwitter);
                if (twitterFeeds?.Count > 0)
                {
                    TwitterName = twitterFeeds[0].user.name;
                }
                return(twitterFeeds);
            }

            return(null);
        }
        static void Main(string[] args)
        {
            Console.Write("Write hashtags words, separated with ',' and without '#' char:");
            List <string> keywords = Console.ReadLine().Split(',').ToList();

            Console.Write("Write languages for tweets, separated with ',' (ex. en, es):");
            List <string> languages = Console.ReadLine().Split(',').ToList();

            Console.Write("Write pairs of coordinates for tweets located from the inbox(es) created, separated with ',' (ex. -122.75,36.8,-121.75,37.8 for tweets from San Francisco):");
            List <string> boxCoordinates = Console.ReadLine().Split(',').ToList();

            while (boxCoordinates.Count % 4 != 0)
            {
                Console.Write("Non multiple of 4 number of coordinates detected, please add a pair number of coordinates (or none for avoid) (ex. -122.75,36.8,-121.75,37.8 for tweets from San Francisco):");
                boxCoordinates = Console.ReadLine().Split(',').ToList();
            }

            List <MapBoxCoordinates> mapBoxCoordinates = new List <MapBoxCoordinates>();

            for (int i = 0; i < boxCoordinates.Count; i = i + 4)
            {
                mapBoxCoordinates.Add(
                    new MapBoxCoordinates(decimal.Parse(boxCoordinates[i].Replace('.', ',')),
                                          decimal.Parse(boxCoordinates[i + 1].Replace('.', ',')),
                                          decimal.Parse(boxCoordinates[i + 2].Replace('.', ',')),
                                          decimal.Parse(boxCoordinates[i + 3].Replace('.', ','))));
            }

            TwitterApiClient twitterApiClient = new TwitterApiClient(new HTTP.Helpers.HttpInvoker());

            twitterApiClient.SetCredentials("jkuG56zlta1exJJ3kGi2mlXRM"
                                            , "kPHXBkmLqOV9thDnFE4QJpvzND7hkJBp8AYtwcIts9l64LEmt8"
                                            , "430727651-vHPtvToq1UK3RHm3tMrQmQA4BW3PdJlxAopL53We"
                                            , "rEArJ1vb8Uuh24WTeh9tW8DKFPNWfEvEFte3jdfUkXaPC");

            twitterApiClient.StartStreamingTweets("dummykey", keywords, languages, mapBoxCoordinates, (object sender, TweetStreamArgs e) =>
            {
                if (e.Tweet != null)
                {
                    Console.WriteLine(e.Tweet.text);
                    Console.WriteLine();
                }
            });


            //Task<string> result = TwitterApiClient.getInstance().Tweet(input);
            //Task<string> result2 = TwitterApiClient.getInstance().DirectMessage("testaccountjlc", input);
            //Task<string> result3 = TwitterApiClient.getInstance().ReTweetLastMessage("josep_lagunas");
            //Task<string> result4 = TwitterApiClient.getInstance().ReTweetMessage(903541646029185024);
            //Task<string> result5 = TwitterApiClient.getInstance().ReTweetMessage(903619996970094592, "Aixó és NOU  retweet amb missatge:");
            //Task.WaitAll(result, result2, result3, result4, result5);

            //Console.WriteLine(result.Result);
            //Console.WriteLine();
            //Console.WriteLine();
            //Console.WriteLine(result2.Result);
            //Console.WriteLine();
            //Console.WriteLine();
            //Console.WriteLine(result3.Result);
            //Console.WriteLine();
            //Console.WriteLine();
            //Console.WriteLine(result4.Result);
            //Console.WriteLine();
            //Console.WriteLine();
            //Console.WriteLine(result5.Result);
            Console.ReadKey();
        }