Should I fasten brackets to the wall or desktop first?
As you're just asking about which order to attach the pieces, and not different methods, there is very little difference. 

Mounting the brackets to the wall first may make it easier to ensure you hit studs, but you'll have to be careful to make them exactly level with each other. Attaching them to the desk first ensures they are level, but you'll need to measure more carefully to get the spacing right so you hit studs. Neither is really difficult to get right, just different considerations.

It may be slightly easier to hold the brackets in place without a heavy desk on top.

If you are using any kind of joinery to attach the brackets to the desk (other than screws into the underside of the desk), you'll want to do that before mounting it to the wall, of course.

Another consideration is how much clearance you have below the desk; with little or no clearance, you'll have to attach the brackets to the desk first.