This happened in 444BC. Nehemiah was perhaps taking something of a risk to appear so downcast in the presence of the king. We see in this incident a number of important features. First, Nehemiah prayed. This is often referred to as an arrow prayer, ie one just shot out quickly. Prayer is an important feature of Nehemiah's life and was vital to his success.
A second feature is the interaction with secular authorities. On the one hand he seeks and finds favour from the king, who, we must remember, was a pagan king. Nehemiah asked for what he needed and the king gladly supplied it. Nehemiah puts this down to the gracious hand of God on his life. We need to realise that the grace of God works in our lives to enable us to achieve His purposes. When we are committed to the will of God we will experience more grace. At the same time the years of faithful service no doubt played a role in the king being favourable towards Nehemiah.
Then we get the opposition of Sanballat. He was governor of Samaria (4:1,2) and probably saw his position being threatened. So Nehemiah experiences both favour and opposition from secular authority. There are often debates within the church about whether or not we should seek help from secular authorities (eg taking lottery money). There is no one answer to this. In the Bible we see times when godless rulers help God's people, and we see times when they oppose God's people. We also see times when supposedly godly men oppose God's people!