Beispiel #1
0
        public async Task<Account> GetTwitterAccount(string userId, string screenName)
        {
            var authTwitter = new SingleUserAuthorizer
            {
                CredentialStore = new SingleUserInMemoryCredentialStore
                {
                    ConsumerKey = twitterAuthenticationSettings.Value.ConsumerKey,
                    ConsumerSecret = twitterAuthenticationSettings.Value.ConsumerSecret,
                    OAuthToken = twitterAuthenticationSettings.Value.OAuthToken,
                    OAuthTokenSecret = twitterAuthenticationSettings.Value.OAuthSecret,

                    UserID = ulong.Parse(userId),
                    ScreenName = screenName
                }
            };

            await authTwitter.AuthorizeAsync();

            var twitterCtx = new TwitterContext(authTwitter);

            //VERY important you explicitly keep the "== true" part of comparison. ReSharper will prompt you to remove this, and if it does, the query will not work
            var account = await (from acct in twitterCtx.Account
                                 where (acct.Type == AccountType.VerifyCredentials) && (acct.IncludeEmail == true)
                                 select acct).SingleOrDefaultAsync();

            return account;
        }
        static async Task DoStuffAsync()
        {
            var auth = new SingleUserAuthorizer
            {
                CredentialStore = new SingleUserInMemoryCredentialStore
                {
                    ConsumerKey = "9MUpnlPtNbKYNmJt5jsLaPIQM",
                    ConsumerSecret = "OzBCWTLC4QVn5081LhcRPV6DDbjzUh53nvlUhNmbOy5KoK8aFA",
                    AccessToken = "18138503-SSeuXTfCxyYeBzSu1afhUAsKTX59iJ4UK4zObfmEt",
                    AccessTokenSecret = "9zNHI9DYGVYl7n4dZs8VlsCT6T8W5WHRd4uY7wQAm1lp5",
                }
            };

            await auth.AuthorizeAsync();

            var twitterContext = new TwitterContext(auth);
            await LoadExistingTwitterFriends(twitterContext);
        }
Beispiel #3
0
        public TwitterService(IConfigurationRoot configuration)
        {
            this.configuration = configuration;

            var auth = new SingleUserAuthorizer
            {
                CredentialStore = new SingleUserInMemoryCredentialStore
                {
                    ConsumerKey = configuration["Twitter:ConsumerKey"],
                    ConsumerSecret = configuration["Twitter:ConsumerSecret"],
                    AccessToken = configuration["Twitter:AccessToken"],
                    AccessTokenSecret = configuration["Twitter:AccessTokenSecret"]
                }
            };

            auth.AuthorizeAsync().Wait();

            twitterContext = new TwitterContext(auth);
        }
Beispiel #4
0
        public static TwitterContext GetTwitterContext(WallModel model)
        {
            var auth = new SingleUserAuthorizer
            {
                CredentialStore = new InMemoryCredentialStore
                {
                    ConsumerKey = model.ConsumerKey,
                    ConsumerSecret = model.ConsumerSecret,
                    OAuthToken = model.UserTokenKey,
                    OAuthTokenSecret = model.UserTokenSecret,
                }
            };

            auth.AuthorizeAsync();

            auth.AccessType = AuthAccessType.Write;

            return new TwitterContext(auth);
        }
Beispiel #5
0
        /// <summary>
        /// Authorizes against Twitter.
        /// </summary>
        /// <returns></returns>
        private async Task<IAuthorizer> AuthorizeAsync()
        {
            ServiceEventSource.Current.ServiceMessage(this, "Twitter: Authorizing");
            try
            {
                #region string consumerKey, consumerSecret, accessToken, accessTokenSecret = ...

                string consumerKey = Environment.GetEnvironmentVariable("TweeterConsumerKey");
                string consumerSecret = Environment.GetEnvironmentVariable("TweeterConsumerSecret");
                string accessToken = Environment.GetEnvironmentVariable("TwitterAccessToken");
                string accessTokenSecret = Environment.GetEnvironmentVariable("TwitterAccessTokenSecret");

                if (string.IsNullOrEmpty(consumerKey))
                {
                    var config = this.ServiceInitializationParameters
                        .CodePackageActivationContext
                        .GetConfigurationPackageObject("Config")
                        .Settings.Sections["TwitterCredentials"]
                        .Parameters;

                    consumerKey = config["TweeterConsumerKey"]?.Value;
                    consumerSecret = config["TweeterConsumerSecret"]?.Value;
                    accessToken = config["TwitterAccessToken"]?.Value;
                    accessTokenSecret = config["TwitterAccessTokenSecret"]?.Value;
                }

                #endregion // string consumerKey, consumerSecret, accessToken, accessTokenSecret = ...

                var auth = new SingleUserAuthorizer()
                {
                    CredentialStore = new SingleUserInMemoryCredentialStore
                    {
                        ConsumerKey = consumerKey,
                        ConsumerSecret = consumerSecret,
                        AccessToken = accessToken,
                        AccessTokenSecret = accessTokenSecret
                    }
                };

                await auth.AuthorizeAsync();
                ServiceEventSource.Current.ServiceMessage(this, "Twitter: Authorized");

                return auth;
            }
            #region Exception Handling

            catch (Exception ex)
            {
                var id = Constants.Singleton;
                var proxy = ActorProxy.Create<IImdbFaults>(id);
                await proxy.ReportError($"Twitter Authorization failed: {ex}");

                ServiceEventSource.Current.ServiceHostInitializationFailed(ex);
                throw;
            }

            #endregion // Exception Handling
        }