There are several ways that you can get gems and they are listed below.
Daily Online and Weekly Log-in.
You will be awarded a level 1 gem pack after every 45 minutes of gameplay and a level 3 gem pack on the 5th day of a weekly log-in.
Tasks
Completing the in-game limited-time activity tasks will earn you gems. These tasks generally involve reaching appointed levels.
Achievenments
There is the possibility when some achievements have been unlocked that you will be awarded gems.
Mall
You can get Gems directly in the Mall with ingot. To enter the Mall function click on the 'Bedroom' button at the top left of the screen of the 'Main' menu.
Faction Shop
You can use Faction Contribution to buy gems. The number of gems that will be available in the faction shop is limited and will depend on what the faction level is. The higer the faction level, the more gems in the store.
Errand
Once you have cleared the 28th stage in the game the Errand activity will become open to you in the Imperial Garden. What Errand does is set a task for you to perform and once completed you will be compensated with a reward that can sometimes be gems. If you enlist a requested hero when undertaking an Errand it will enhance the quality of rewards you get upon completing the task. When you initially get access to the Errand Palace itself a lot of buildings are inaccessible and only become unlocked when you have worked your way up the ladder (rank-wise).