We investigate bubbling solutions for the nonlocal equation A^s_{\Omega} u =u^p,\ u > 0 \quad \text{in } \Omega, under homogeneous Dirichlet conditions, where \Omega is a bounded and smooth domain. The operator A^s_{\Omega} stands for two types of nonlocal operators that we treat in a unified way: either the spectral fractional Laplacian or the restricted fractional Laplacian. In both cases s \in (0,1) , and the Dirichlet conditions are different: for the spectral fractional Laplacian, we prescribe u=0 on \partial \Omega , and for the restricted fractional Laplacian, we prescribe u=0 on \mathbb R^n \backslash \Omega . We construct solutions when the exponent p = (n+2s)/(n-2s) \pm \epsilon is close to the critical one , concentrating as \epsilon \to 0 near critical points of a reduced function involving the Green and Robin functions of the domain.