Needle shape monitoring techniques ensure the safety of modern interventional surgery. Optical fiber sensors such as fiber Bragg grating (FBG) are being increasingly employed for needle shape sensing. However, existing studies have overlooked the simultaneous strain and temperature sensitivities of the sensors in the fiber grating sensing array, directly affecting the shape reconstruction accuracy under variable temperature environments. Thus, this study proposed a method to optimize shape reconstruction-based fiber optic sensing by introducing a strain and temperature sensitivity matrix. First, the relationship between the wavelength shift of the fiber grating implanted in the needle and its strain and temperature was analyzed based on the fiber grating sensing theory. Thereafter, the strain sensitivity matrix was introduced to improve the accuracy of the shape reconstruction algorithm. Moreover, temperature compensation eliminated temperature influence on the sensor. Next, the local unit geometric parameter relationship and coordinate transformation equation of the needle were derived, and the shape sensing model of the FBG array-based needle was established. Finally, the effectiveness of the method was verified by conducting variable temperature shape reconstruction experiments. The proposed method had increased accuracy over the conventional method in shape reconstruction under variable temperature environments, thus indicating its superiority and application feasibility.