Drupal 8 Configuration API - cant access variables I have made a simple example to practice using the configuration api in drupal 8. I created the following twitter_pull.credentials.yml file in the config/install folder:

oauth_access_token: "12345"
oauth_access_token_secret: "67890"
consumer_key: "54321"
consumer_secret: "09876"


and flushed my cache. In a custom block, I pulled in the configuration

$config = \Drupal::config('twitter_pull.credentials');


and when I did a dpm

dpm($config);


I did not get a null result. However, when I tried accessing a property:

drupal_set_message($config-&gt;get('consumer_key'));


now the result was null. Even when I tried using a configuration object which already exists

 $enabled = \Drupal::config('system.maintenance')-&gt;get('enabled');
dpm($enabled);


it still returned null. What am I missing here?

EDIT:
If it helps anything here is the full code:



namespace Drupal\twitter_pull\Plugin\Block;
use Drupal\block\BlockBase;

/**
 * Provides a block for executing PHP code.
 *
 * @Block(
 *   id = "twitter_pull_tweets_block",
 *   admin_label = @Translation("Twitter Tweets")
 * )
 */
class TweetsBlock extends BlockBase {

  /**
   * Builds and returns the renderable array for this block plugin.
   *
   * @return array
   *   A renderable array representing the content of the block.
   *
   * @see \Drupal\block\BlockViewBuilder
   */
  public function build() {
    $config = \Drupal::config('twitter_pull.credentials');
    $enabled = \Drupal::config('system.maintenance')->get('enabled');
    dpm($enabled);
    dpm($config);
    drupal_set_message($enabled);
    return 'this is a block: ' . $config->get('consumer_key');
  }
}
To elaborate on @dawehner's answers, default configuration is not cached.

It is only imported when you install a module. After that, if you make changes to default configuration, the only way to add it to existing installations is to write an update function that adds it manually.

During development, there are modules like Configuration development, that can automate that process, but they will obviously not be present on any productive installations.