What is the passive voice of the following sentence?
My friend gave me this book.
I was given this book by my friend.
This book was given to me by my friend.
Both of your sentences are acceptable, but they're passive versions of two different sentences.
Your original sentence can be rephrased:
1a. My friend gave me this book.
1b. My friend gave this book to me.
These two sentences have the same meaning, but they differ grammatically. In the latter sentence me is part of the preposition phrase to me.
The relationship between these two sentences is sometimes referred to by linguists as the dative alternation. In English Verb Classes and Alternations: A Preliminary Investigation, Beth Levin lists several types of verbs which participate in this alternation, for example:
Give, of course, fits in the first category, but we can do the same thing with any of the verbs listed above:
2a. She handed me the letter.
2b. She handed the letter to me.
Because your sentence can be rephrased this way, we can come up with a passive version of either one, and they end up having the same meaning:
3a. My friend gave me this book. ← active
3b. I was given this book by my friend. ← passive
4a. My friend gave this book to me. ← active
4b. This book was given to me by my friend. ← passive
Example 4b has to because its active equivalent also had to. This means that example 4b is not a direct passive equivalent of your sentence, but it can be used and has the same meaning.
Because example 3a is ditransitive, in principle it is also possible to make another passive by promoting its direct object (this book) to subject position:
5a. My friend gave me this book. ← active
5b. This book was given me by my friend. ← passive
However, speakers are much more likely to say sentences 3b or 4b. Not all speakers will find example 5b acceptable, and it is particularly likely to sound odd to American English speakers. You should be able to understand this sort of passive if you come across it, but to be safe I suggest you avoid using it yourself.
So as you can see, both of your sentences are acceptable, but only I was given this book by my friend is a direct passive equivalent of your active example.