Advertisement
AlexHagerman

Linq2Twitter WCF

Sep 27th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Serialization;
  5. using System.ServiceModel;
  6. using System.ServiceModel.Web;
  7. using System.Text;
  8. using LinqToTwitter;
  9. using System.Configuration;
  10.  
  11. namespace Twitter.WCF
  12. {
  13.     public class Tweets
  14.     {
  15.         public List<Search> GetTweets()
  16.         {
  17.             var auth = new SingleUserAuthorizer
  18.             {
  19.                 Credentials = new SingleUserInMemoryCredentials
  20.                 {
  21.                     ConsumerKey =
  22.                         ConfigurationManager.AppSettings["twitterConsumerKey"],
  23.                     ConsumerSecret =
  24.                         ConfigurationManager.AppSettings["twitterConsumerSecret"],
  25.                     TwitterAccessToken =
  26.                         ConfigurationManager.AppSettings["twitterAccessToken"],
  27.                     TwitterAccessTokenSecret =
  28.                         ConfigurationManager.AppSettings["twitterAccessTokenSecret"]
  29.                 }
  30.             };
  31.  
  32.             var twitterCtx = new TwitterContext(auth);
  33.  
  34.             var srch =
  35.                 (from search in twitterCtx.Search
  36.                  where search.Type == SearchType.Search &&
  37.                        search.Query == "Hospital" &&
  38.                        search.Count == 25
  39.                  select search)
  40.                 .ToList();
  41.  
  42.             return srch;
  43.         }
  44.  
  45.         public IQueryable<Search> SearchResults
  46.         {
  47.             get
  48.             {
  49.                 return GetTweets().AsQueryable();
  50.             }
  51.         }
  52.     }
  53. }
  54.  
  55.  
  56. //------------------------------------------------------------------------------
  57. // <copyright file="WebDataService.svc.cs" company="Microsoft">
  58. //     Copyright (c) Microsoft Corporation.  All rights reserved.
  59. // </copyright>
  60. //------------------------------------------------------------------------------
  61. using System;
  62. using System.Collections.Generic;
  63. using System.Data.Services;
  64. using System.Data.Services.Common;
  65. using System.Linq;
  66. using System.ServiceModel.Web;
  67. using System.Web;
  68.  
  69. namespace Twitter.WCF
  70. {
  71.     public class Twitter : DataService<Tweets>
  72.     {
  73.         public static void InitializeService(DataServiceConfiguration config)
  74.         {
  75.             config.SetEntitySetAccessRule("SearchResults", EntitySetRights.AllRead);
  76.             config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
  77.             config.UseVerboseErrors = true;
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement