The two sentences you've described are both possible grammatically, but have different meanings (the second one describes a rather unusual situation, and would not often be heard). 1. " means John posted a photo showing him (John) with his (John's) friend.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.
wisdom27Jhon posted a photo of him with his friend.There are two interpretations of this one. The second one below is less likely.