The song is played during the opening credits for Toy Story and Toy Story 3, establishing the importance of Woody and Andy in the first film and the importance of all his toys in the third. Toy Story 3 also uses it for irony and dramatic effect, as the opening credits harken back to the first film and the song abruptly fades out with "As the years go by/Our friendship will never die", before showing that Andy's remaining toys in the present day are boxed up and unused.
In the two sequels, the song is listened to by the characters as part of the story. Two of these are cover versions done at the end of the film for thematic reasons: at the end of Toy Story 2, the character Wheezy starts to sing it to the other toys; during the end credits of Toy Story 3, Buzz Lightyear and Jessie (now a couple) perform a pasodoble to a Spanish version of the song, deliberately played by Jessie to get Buzz to dance.
The most significant use of the song was in the third act of Toy Story 2, where an episode of Woody's Roundup (the 1950s puppet show he was based on) shows the puppet Woody singing the song, directed at the young audience and featuring a small child hugging the puppet. Woody sees this and has an epiphany, realizing that his mission as a toy is to be there for a child. (In-universe, the song was presumably written for Woody's Roundup.)
The Woody's Roundup version was performed by Tom Hanks, with acoustic guitar backing; Wheezy's version was sung by Robert Goulet (though the character was voiced by Joe Ranft); and the Spanish version, "You've Got a Friend in Me (Para el Buzz Español)", performed by the Gipsy Kings.
Jennifer Hammond arranged this song and other themes from the films for the Toy Story Midway Mania! attraction (in a more carnival-style). It or another version of it can be heard at the official Toy Story website, under "Games" and "Toy Story Mania!".
Another Spanish version of the song, titled "Yo Soy Tu Amigo Fiel!" (Spanish for "I am Your Faithful Friend!"), was covered by Aleks Syntek and Danna Paola.
The German version of the song is titled "Du hast 'nen Freund in mir". The title and the song itself is a fairly direct translation of the English original. Artists such as Klaus Lage have posted cover versions on the internet.