Beispiel #1
0
        /// <summary>
        /// Set the bearer token onto a set of credentials
        /// </summary>
        /// <param name="credentials">Credentials to update</param>
        /// <param name="force">Set the bearer token even if it is not required for executing queries</param>
        public static void InitializeApplicationOnlyCredentials(ITwitterCredentials credentials = null, bool force = false)
        {
            credentials = credentials ?? CredentialsAccessor.CurrentThreadCredentials;

            if (credentials == null)
            {
                throw new TwitterNullCredentialsException("Initialize Application Bearer needs to either have a" +
                                                          " credentials parameter or have the thread credentials set up.");
            }

            var isBearerAlreadySet = !string.IsNullOrEmpty(credentials.ApplicationOnlyBearerToken);
            var isBearerRequired   = string.IsNullOrEmpty(credentials.AccessToken) || string.IsNullOrEmpty(credentials.AccessTokenSecret);

            if (force || (isBearerRequired && !isBearerAlreadySet))
            {
                AuthFactory.InitializeApplicationBearer(credentials);
            }
        }