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)); }
public object Any(Search request) { TwitterOAuthClient client = new TwitterOAuthClient { ConsumerKey = "sz5EPgUcZQQAyAkp3LrlgHrMZ", ConsumerSecret = "wC2TIL67sIbELO6OYgaTg2RE3ctH1TTRkC0q0hpisWyztThBg1", Token = "189161034-KoBoQR97ZdailKAAdVLK63gaM2yUlnhN9tQuOSJ8", TokenSecret = "k7P8TsvpyqyMwOrPh7mOgSgILVvMFFglj1LhAvSa5KEoc" }; var twitter = TwitterService.CreateFromOAuthClient(client); var results = new List <Comment>(); TwitterSearchTweetsResponse response = twitter.Search.GetTweets("#" + request.Keyword); foreach (TwitterStatusMessage tweet in response.Body.Statuses) { results.Add(new Comment { Description = tweet.Text, Provider = "Twitter" }); } return(results); }
/// <summary> /// Initializes a new instance from the specified <see cref="TwitterOAuthClient"/>. /// </summary> /// <param name="client">An instance of <see cref="TwitterOAuthClient"/>.</param> /// <returns>Returns a new instance of <see cref="TwitterService"/>.</returns> 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.Geocode = new TwitterGeocodeEndpoint(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); }
/// <summary> /// Initializes a new instance from the specified <see cref="TwitterOAuthClient"/>. /// </summary> /// <param name="client">An instance of <see cref="TwitterOAuthClient"/>.</param> /// <returns>A new instance of <see cref="TwitterService"/>.</returns> public static TwitterService CreateFromOAuthClient(TwitterOAuthClient client) { if (client == null) { throw new ArgumentNullException(nameof(client)); } return(new TwitterService(client)); }
static void Main(string[] args) { var client = new TwitterOAuthClient(); var response = client.ObterURL(Guid.Parse("5F22E669-8CF2-4702-A828-B32E832A6BA6"), "voraxgg"); Console.Write("URL", response.Item); }
public MainPage() { this.InitializeComponent(); this.twitterOAuth = new TwitterOAuthClient(new ConsumerInfo() { OAuthCallbackUrl = TwitterOAuthConstants.OAuthCallbackUrl, OAuthConsumerKey = TwitterOAuthConstants.ConsumerKey, OAuthConsumerSecret = TwitterOAuthConstants.ConsumerSecret, }); }
public MainWindow() { InitializeComponent(); this.twitterOAuth = new TwitterOAuthClient(new ConsumerInfo() { OAuthCallbackUrl = OAuthCallbackUrl, OAuthConsumerKey = ConsumerKey, OAuthConsumerSecret = ConsumerSecret, }); this.WebBrowser.Visibility = System.Windows.Visibility.Collapsed; }
private TwitterService(TwitterOAuthClient client) { // Set the client Client = client; // Set the endpoints etc. Account = new TwitterAccountEndpoint(this); Favorites = new TwitterFavoritesEndpoint(this); Followers = new TwitterFollowersEndpoint(this); Friends = new TwitterFriendsEndpoint(this); Geocode = new TwitterGeocodeEndpoint(this); Lists = new TwitterListsEndpoint(this); Search = new TwitterSearchEndpoint(this); Statuses = new TwitterStatusesEndpoint(this); Users = new TwitterUsersEndpoint(this); }
protected override void Render(HtmlTextWriter writer) { if (SPContext.Current != null && SPContext.Current.Web != null && SPContext.Current.Web.CurrentUser != null) { if (Settings != null) { if (Settings.twitter_allow && !string.IsNullOrWhiteSpace(Settings.twitter_oauth_token) && !string.IsNullOrWhiteSpace(Settings.twitter_oauth_token_secret)) { TwitterOAuthClient client = new TwitterOAuthClient { ConsumerKey = ConsumerKey, ConsumerSecret = ConsumerSecret, Token = Settings.twitter_oauth_token, TokenSecret = Settings.twitter_oauth_token_secret, Callback = this.Page.Request.Url.AbsoluteUri }; try { TwitterService service = TwitterService.CreateFromOAuthClient(client); TwitterUser user = service.Account.VerifyCredentials(); if (user != null) { System.Web.UI.WebControls.Literal literal = new Literal(); literal.Text += "<pre><b>Id</b> " + user.Id + "</pre>"; literal.Text += "<pre><b>ScreenName</b> " + user.ScreenName + "</pre>"; literal.Text += "<pre><b>Name</b> " + user.Name + "</pre>"; literal.Text += "<pre><b>Avatar</b> " + user.ProfileImageUrlHttps + "</pre>"; literal.Text += "<pre><b>Url</b> " + user.Url + "</pre>"; literal.Text += "<pre><b>Description</b> " + user.Description + "</pre>"; literal.Text += "<img src=\"" + user.ProfileImageUrlHttps + "\" alt=\"\" />\n"; pnl_twitter.Controls.Add(literal); } } catch (Exception) { throw; } } } } base.Render(writer); }
public ActionResult LinkTwitter() { string rootUrl = Request.Url.GetLeftPart(UriPartial.Authority); TwitterOAuthClient client = new TwitterOAuthClient(); client.ConsumerKey = WebConfigurationManager.AppSettings["twitterConsumerKey"]; client.ConsumerSecret = WebConfigurationManager.AppSettings["twitterConsumerSecret"]; client.Callback = rootUrl + "/umbraco/surface/Profile/LinkTwitter"; // Make the request to the Twitter API to get a request token SocialOAuthRequestTokenResponse response = client.GetRequestToken(); // Get the request token from the response body TwitterOAuthRequestToken requestToken = (TwitterOAuthRequestToken)response.Body; // 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 return(Redirect(requestToken.AuthorizeUrl)); }
internal TwitterAccountRawEndpoint(TwitterOAuthClient client) { Client = client; }
internal TwitterFriendsRawEndpoint(TwitterOAuthClient client) { Client = client; }
protected new void Page_Load(object sender, EventArgs e) { base.Page_Load(sender, e); if (SPContext.Current != null && SPContext.Current.Web != null && SPContext.Current.Web.CurrentUser != null) { if (Settings != null) { TwitterOAuthClient client = new TwitterOAuthClient { ConsumerKey = ConsumerKey, ConsumerSecret = ConsumerSecret, Callback = this.Page.Request.Url.AbsoluteUri }; OAuthRequestToken token; if ((OAuthToken == null) && (!Settings.twitter_allow && string.IsNullOrWhiteSpace(Settings.twitter_oauth_token) && string.IsNullOrWhiteSpace(Settings.twitter_oauth_token_secret))) { token = client.GetRequestToken(); Settings.twitter_oauth_token = token.Token; Settings.twitter_oauth_token_secret = token.TokenSecret; Client.SetClubCloudSettings(Settings); Response.Redirect(token.AuthorizeUrl); } else { client.Token = Settings.twitter_oauth_token; client.TokenSecret = Settings.twitter_oauth_token_secret; if (!Settings.twitter_allow) { try { OAuthAccessToken accessToken = client.GetAccessToken(OAuthVerifier); client.Token = accessToken.Token; client.TokenSecret = accessToken.TokenSecret; Settings.twitter_oauth_token = accessToken.Token; Settings.twitter_oauth_token_secret = accessToken.TokenSecret; Settings.twitter_allow = true; } catch (Exception) { Settings.twitter_allow = false; Settings.twitter_oauth_token = null; Settings.twitter_oauth_token_secret = null; } Client.SetClubCloudSettings(Settings); } } } /* * if(settings.twitter_allow) * { * //TwitterAccessInformation information = new TwitterAccessInformation * //twitterConnect.OAuthToken = settings.twitter_oauth_token; * //twitterConnect.OAuthTokenSecret = settings.twitter_oauth_token_secret; * * //twitterConnect.Tweet("integration test"); * //DataTable data = twitterConnect.FetchProfile("MijnClubCloud"); * //int count = data.Rows.Count; * } */ //} } else { this.pnl_twitter.Visible = false; this.pnl_secure.Visible = true; } }
public ActionResult LinkTwitter(string oauth_token, string oauth_verifier) { // Get the member of the current ID int memberId = Members.GetCurrentMemberId(); if (memberId <= 0) { return(GetErrorResult("Oh noes! An error happened.")); } try { IPublishedContent profilePage = Umbraco.TypedContent(1057); if (profilePage == null) { return(GetErrorResult("Oh noes! This really shouldn't happen.")); } // Initialize the OAuth client TwitterOAuthClient client = new TwitterOAuthClient(); client.ConsumerKey = WebConfigurationManager.AppSettings["twitterConsumerKey"]; client.ConsumerSecret = WebConfigurationManager.AppSettings["twitterConsumerSecret"]; // Grab the request token from the session SocialOAuthRequestToken requestToken = Session[oauth_token] as SocialOAuthRequestToken; if (requestToken == null) { return(GetErrorResult("Session expired? Please click the link below and try to link with your Twitter account again ;)")); } // Update the OAuth client with information from the request token client.Token = requestToken.Token; client.TokenSecret = requestToken.TokenSecret; // Make the request to the Twitter API to get the access token SocialOAuthAccessTokenResponse response = client.GetAccessToken(oauth_verifier); // Get the access token from the response body TwitterOAuthAccessToken accessToken = (TwitterOAuthAccessToken)response.Body; // Update the OAuth client properties client.Token = accessToken.Token; client.TokenSecret = accessToken.TokenSecret; // Initialize a new service instance from the OAUth client var service = Skybrud.Social.Twitter.TwitterService.CreateFromOAuthClient(client); // Get some information about the authenticated Twitter user TwitterAccount user; try { // Initialize the options for the request (we don't need the status) var options = new TwitterVerifyCrendetialsOptions { SkipStatus = true }; // Make the request to the Twitter API var userResponse = service.Account.VerifyCredentials(options); // Update the "user" variable user = userResponse.Body; } catch (Exception ex) { LogHelper.Error <ProfileController>("Unable to get user information from the Twitter API", ex); return(GetErrorResult("Oh noes! An error happened.")); } // Get a reference to the member searcher BaseSearchProvider searcher = ExamineManager.Instance.SearchProviderCollection["InternalMemberSearcher"]; // Initialize new search criteria for the Twitter screen name ISearchCriteria criteria = searcher.CreateSearchCriteria(); criteria = criteria.RawQuery($"twitter:{user.ScreenName}"); // Check if there are other members with the same Twitter screen name foreach (var result in searcher.Search(criteria)) { if (result.Id != memberId) { LogHelper.Info <ProfileController>("Failed setting Twitter screen name for user with ID " + memberId + ". Username is already used by member with ID " + result.Id + "."); return(GetErrorResult("Another member already exists with the same Twitter screen name.")); } } // Get the member from the member service var ms = ApplicationContext.Services.MemberService; var mem = ms.GetById(memberId); // Update the "twitter" property and save the value mem.SetValue("twitter", user.ScreenName); mem.SetValue("twitterId", user.IdStr); mem.SetValue("twitterData", user.JObject.ToString()); ms.Save(mem); // Clear the runtime cache for the member ApplicationContext.ApplicationCache.RuntimeCache.ClearCacheItem("MemberData" + mem.Username); // Redirect the member back to the profile page return(RedirectToUmbracoPage(1057)); } catch (Exception ex) { LogHelper.Error <ProfileController>("Unable to link with Twitter user for member with ID " + memberId, ex); return(GetErrorResult("Oh noes! An error happened.")); } }
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 }
protected void Page_Load(object sender, EventArgs e) { // Initialize a new OAuth client with information about your app TwitterOAuthClient oauth = new TwitterOAuthClient { ConsumerKey = "1RA07SxkMPDrnTf5wx4fNQU9v", ConsumerSecret = "zsalItDzjWcAg3KWEQPv7UeVCRwR2neLQD0dihlKZ6WYJDnNA7", Callback = "https://b7b326cf8125.ngrok.io/WebForm1.aspx" }; if (Request.QueryString["do"] == "login") { // Get a request token from the Twitter API OAuthRequestToken token = oauth.GetRequestToken(); // Save the token information to the session so we can grab it later Session[token.Token] = token; // Redirect the user to the authentication page at Twitter.com Response.Redirect(token.AuthorizeUrl); } else if (Request.QueryString["oauth_token"] != null) { // Get OAuth parameters from the query string string oAuthToken = Request.QueryString["oauth_token"]; string oAuthVerifier = Request.QueryString["oauth_verifier"]; // Grab the request token from the session OAuthRequestToken token = Session[oAuthToken] as OAuthRequestToken; if (token == null) { // Content.Text = "<p>An error occured. Timeout?</p>"; } else { // Some information for development purposes // Content.Text += "<p>Request Token: " + token.Token + "</p>"; // Content.Text += "<p>Request Token Secret: " + token.TokenSecret + "</p>"; // Update the OAuth client with information from the request token oauth.Token = token.Token; oauth.TokenSecret = token.TokenSecret; try { // Obtain an access token from the request token and OAuth verifier OAuthAccessToken accessToken = oauth.GetAccessToken(oAuthVerifier); // Update the OAuth client with the access token and access token secret oauth.Token = accessToken.Token; oauth.TokenSecret = accessToken.TokenSecret; TwitterVerifyCrendetialsOptions options = new TwitterVerifyCrendetialsOptions { IncludeEmail = true }; // Initialize a new TwitterService instance based on the OAuth client TwitterService service = TwitterService.CreateFromOAuthClient(oauth); // Get information about the authenticated user var user = service.Account.VerifyCredentials(options); // Some information for development purposes // Content.Text += "<b>Hi " + (user.Name ?? user.ScreenName) + "</b> (" + user.Id + ")<br />"; // Content.Text += "<p>Access Token: " + accessToken.Token + "</p>"; // Content.Text += "<p>Access Token Secret: " + accessToken.TokenSecret + "</p>"; } catch (Exception ex) { // Content.Text += "<pre style=\"color: red;\">" + ex.GetType().FullName + ": " + ex.Message + "\r\n\r\n" + ex.StackTrace + "</pre>"; } } } else if (Request.QueryString["denied"] != null) { // Get OAuth parameters from the query string string oAuthToken = Request.QueryString["denied"]; // Remove the request token from the session Session.Remove(oAuthToken); // Write some output for the user /// Content.Text += "<p>It seems that you cancelled the login!</p>";/ /// / Content.Text += "<p><a href=\"OAuth.aspx?do=login\">Try again?</a></p>"; } else { // Content.Text += "<p><a href=\"OAuth.aspx?do=login\">Login with Twitter</a></p>"; } }
public adduohelper.ResponseEnvelope Enviar() { var client = new TwitterOAuthClient(); return(client.RegistrarPerfil(twitterOAuthResponse)); }
internal TwitterUsersRawEndpoint(TwitterOAuthClient client) { Client = client; }
internal TwitterGeocodeRawEndpoint(TwitterOAuthClient client) { Client = client; }
internal TwitterFavoritesRawEndpoint(TwitterOAuthClient client) { Client = client; }
public adduohelper.ResponseEnvelope <string> Enviar() { var client = new TwitterOAuthClient(); return(client.ObterURL(empresaId, contaRedeSocial)); }
internal TwitterStatusesRawEndpoint(TwitterOAuthClient client) { Client = client; }
internal TwitterSearchRawEndpoint(TwitterOAuthClient client) { Client = client; }
internal TwitterListsRawEndpoint(TwitterOAuthClient client) { Client = client; }