public static TwitterService CreateFromOAuthClient(TwitterOAuthClient client) { // This should never be null if (client == null) throw new ArgumentNullException("client"); // Initialize the service TwitterService service = new TwitterService { Client = client }; // Set the endpoints etc. service.Account = new TwitterAccountEndpoint(service); service.Favorites = new TwitterFavoritesEndpoint(service); service.Followers = new TwitterFollowersEndpoint(service); service.Friends = new TwitterFriendsEndpoint(service); service.Geo = new TwitterGeoEndpoint(service); service.Lists = new TwitterListsEndpoint(service); service.Search = new TwitterSearchEndpoint(service); service.Statuses = new TwitterStatusesEndpoint(service); service.Users = new TwitterUsersEndpoint(service); // Return the service return service; }
public List<UserProfile> SearchTwitter(SocialApp app, string searchText) { var userProfiles = new List<UserProfile>(); // Initialize a new OAuth client from the consumer key and secret var client = new TwitterOAuthClient(app.ApiKey, app.ApiSecret, app.Token, app.TokenSecret); var service = TwitterService.CreateFromOAuthClient(client); var response = service.Users.Search(searchText); //TO DO Url is returning null so had to hard code it with screen name , look at this later return response.Body.Select(u => new UserProfile { ImageUrl = u.ProfileImageUrl, Name = u.Name, ProfileLink = "https://twitter.com/" + u.ScreenName }).ToList(); }
public object GetTweet(long id) { TwitterOAuthClient oauth = new TwitterOAuthClient { ConsumerKey = "sgJtXh7FoPVrizbTX00G8UnCx", ConsumerSecret = "eQpoqMbYgO62FymLDyKridL9rE5kpT7bqfyZ8a2MFnl0xTYvCZ" }; string tweet; try { tweet = oauth.Statuses.GetTweet(id); if (tweet.StartsWith("{\"errors\":")) { return Request.CreateResponse(HttpStatusCode.InternalServerError, new { error = "Unable to retrieve tweet." }); } } catch (Exception) { return Request.CreateResponse(HttpStatusCode.InternalServerError, new { error = "Unable to retrieve tweet." }); } return JsonConvert.DeserializeObject(tweet); }
internal TwitterStatusesRawEndpoint(TwitterOAuthClient client) { Client = client; }
internal TwitterAccountRawEndpoint(TwitterOAuthClient client) { Client = client; }
internal TwitterGeoRawEndpoint(TwitterOAuthClient client) { Client = client; }
internal TwitterUsersRawEndpoint(TwitterOAuthClient client) { Client = client; }
protected void Page_Load(object sender, EventArgs e) { Callback = Request.QueryString["callback"]; ContentTypeAlias = Request.QueryString["contentTypeAlias"]; PropertyAlias = Request.QueryString["propertyAlias"]; // Get the prevalue options TwitterOAuthPreValueOptions options = TwitterOAuthPreValueOptions.Get(ContentTypeAlias, PropertyAlias); if (!options.IsValid) { Content.Text += "<p><strong>ContentTypeAlias</strong> " + ContentTypeAlias + "</p>"; Content.Text += "<p><strong>PropertyAlias</strong> " + PropertyAlias + "</p>"; Content.Text += "Hold on now! The options of the underlying prevalue editor isn't valid."; return; } // Configure the OAuth client based on the options of the prevalue options TwitterOAuthClient client = new TwitterOAuthClient { ConsumerKey = options.ConsumerKey, ConsumerSecret = options.ConsumerSecret, Callback = Request.Url.ToString() }; // Check whether the user has denied the app if (HasUserDenied) { Session.Remove(DeniedToken); Content.Text = "<div class=\"error\">Error: The app was denied access to your account.</div>"; return; } #region OAuth 1.0a - Step 3 if (OAuthToken != null) { // Grab the request token from the session OAuthRequestToken token = Session[OAuthToken] as OAuthRequestToken; // Check whether the requets token was found in the current session if (token == null) { Content.Text = "<div class=\"error\">An error occured. Timeout?</div>"; return; } // Update the token and token secret client.Token = token.Token; client.TokenSecret = token.TokenSecret; // Now get the access token try { OAuthAccessToken accessToken = client.GetAccessToken(OAuthVerifier); client.Token = accessToken.Token; client.TokenSecret = accessToken.TokenSecret; } catch (Exception) { Content.Text = "<div class=\"error\">Unable to retrieve access token from <b>Twitter.com</b>.</div>"; return; } try { // Initialize an instance of TwitterService TwitterService service = TwitterService.CreateFromOAuthClient(client); // Get information about the server TwitterUser user = service.Account.VerifyCredentials().Body; Content.Text += "<p>Hi <strong>" + (String.IsNullOrEmpty(user.Name) ? user.ScreenName : user.Name) + "</strong></p>"; Content.Text += "<p>Please wait while you're being redirected...</p>"; // Set the callback data TwitterOAuthData data = new TwitterOAuthData { Id = user.Id, ScreenName = user.ScreenName, Name = String.IsNullOrEmpty(user.Name) ? "" : user.Name, Avatar = user.ProfileImageUrlHttps, ConsumerKey = client.ConsumerKey, ConsumerSecret = client.ConsumerSecret, AccessToken = client.Token, AccessTokenSecret = client.TokenSecret }; // Update the UI and close the popup window Page.ClientScript.RegisterClientScriptBlock(GetType(), "callback", String.Format( "self.opener." + Callback + "({0}); window.close();", data.Serialize() ), true); } catch (TwitterException ex) { Content.Text = "<div class=\"error\">Error in the communication with Twitter.com<br /><br />" + ex.Message + " (Code: " + ex.Code + ")</div>"; } catch (Exception) { Content.Text = "<div class=\"error\">Error in the communication with Twitter.com</div>"; } return; } #endregion #region OAuth 1.0a - Step 1 // Get a request token from the Twitter API OAuthRequestToken requestToken = client.GetRequestToken(); // Save the token information to the session so we can grab it later Session[requestToken.Token] = requestToken; // Redirect the user to the authentication page at Twitter.com Response.Redirect(requestToken.AuthorizeUrl); #endregion }
internal TwitterFavoritesRawEndpoint(TwitterOAuthClient client) { Client = client; }
internal TwitterListsRawEndpoint(TwitterOAuthClient client) { Client = client; }
internal TwitterFriendsRawEndpoint(TwitterOAuthClient client) { Client = client; }