Recent studies suggest that the relationship between endogenous oxytocin and social affiliative behavior can be critically moderated by contextual and individual factors in humans. While oxytocin has been shown to influence human-directed affiliative behaviors in dogs, no study investigated yet how such factors moderate these effects. Our study aimed to investigate whether the context and the dogs" individual characteristics moderate the associations between the social affiliative (greeting) behavior and four single-nucleotide polymorphisms (SNPs) of the oxytocin receptor (OXTR) gene. We recorded the greeting behavior in three contexts: (1) when the dog first met an unfamiliar experimenter, (2) during a separation from the owner, and (3) after the experimenter approached the dog in a threatening manner. In the latter two contexts (during separation and after threatening), we categorized the dogs into stressed and non-stressed groups based on their behavior in the preceding situations. In line with previous studies, we found that polymorphisms in the OXTR gene are related to the greeting behavior of dogs. However, we also showed that the analyzed SNPs were associated with greeting in different contexts and in different individuals, suggesting that the four SNPs might be related to different functions of the oxytocin system. The -213A/G was associated with greeting only when the dog had no prior negative experience with the experimenter. The rs8679682 was found in association with greeting in all three contexts but these associations were significant only in non-stressed dogs. The -94T/C was associated with greeting only when the dog was stressed and had an interaction with the sex of the dog. The -74C/G SNP was associated with greeting only when the dog was stressed during separation and also had a sex interaction. Taken together, our results suggest that, similarly to humans, the effects of oxytocin on the dogs" social behavior are not universal, but constrained by features of situations and individuals. Understanding these constraints helps further clarify how oxytocin mediates social behavior which, in the long run, could improve the application of oxytocin in pharmacotherapy.