There is a difference between "loving the world" in a positive sense and "loving the world" in a negative sense.
Let's look at John 3:16 in how "God so loved the world that He gave His only begotten son…" Revelation 13:8 tells us Jesus was the "Lamb slain before the foundation of the world," in other words, God knew mankind would sin and would require a remedy to fulfill justice. He loved the world – the creatures He made – enough to provide this ransom price for Adam and provide an opportunity for all to know Him in the kingdom with the curse of sin and death removed.
God IS love (1 John 4:7-12). The Greek word for "love" in John 3:16 is agape or agapao, which is the highest form of love. His very nature is this special, selfless love flowing from everything He does. He acts in the best interest of ALL of His creation.
The Christian is supposed to have agape love for others – love in action – by being kind, forgiving and generous; loving without expecting anything in return. We are even supposed to have this kind of love for our enemies (Matthew 5:44).
When James 4:4 uses the word "world," it means the spirit of the sinful world that is now self-centered instead of God- and Christ-centered. It is selfish and greedy. The faithful Christian lives IN the world but is not OF the world, as they are to be sanctified – set apart – in holiness (1 Thessalonians 5:23). We are to be "ambassadors for Christ" – 2 Corinthians 5:20-21. Ambassadors reside elsewhere but live in a foreign country. Ours is a heavenly hope, but we are residing here in this sinful world and are to be a preserving influence and a reflection of God and His son Jesus (salt and light – Matthew 5:13-16).
We aren't to walk a middle road, trying to keep the favor of God and the favor of the world. Having "friendship of the world" means being in accord with sinful practices, even indirectly. We are to love the world only in the sense of having sympathy with it, like our heavenly Father, but the path of the "present evil world" (Galatians 1:3,4) ruled by Satan (who will be cast out – John 12:31) is out of harmony with God and righteousness.