How to post on Facebook from a Spotify app?

Hey everyone! I’m working on a Spotify app and I’m stuck. I want to add a feature where users can share stuff on their Facebook walls directly from the app. Since Spotify uses Facebook for login, I thought this would be easy. But I haven’t figured out how to make it happen!

I’ve been checking the Spotify API documentation and searching online without any success. Does anyone know if it’s possible to post on a Facebook wall from within the Spotify app? If it works, what API calls should I use?

I came up with something like this but I’m not sure if it’s right:

function shareOnFacebook(textContent) {
  // Retrieve the Facebook token for the current user
  const token = retrieveFBToken();
  
  // Call the Facebook API to share the post
  FB.api('/me/feed', 'POST', 
    { message: textContent, access_token: token },
    function(apiResponse) {
      if (!apiResponse || apiResponse.error) {
        console.error('Failed to share the post on Facebook');
      } else {
        console.log('Successfully shared the post on Facebook');
      }
    }
  );
}

Any suggestions or help would be greatly appreciated. Thanks a lot!

I’ve worked on integrating Facebook sharing into a Spotify app before, and it’s more challenging than it looks.

Spotify’s API doesn’t natively support Facebook posting even though Facebook is used for login. We built a custom solution where the Spotify app communicated with a web service that handled the Facebook API calls for us.

Your approach is on the right track, but you’ll need to separately manage the OAuth flow for Facebook. Also, be aware that the Facebook SDK for JavaScript can simplify client-side integration by handling many complexities for you.