Posting Audio to Facebook Timeline with the Graph API.


Warning: count(): Parameter must be an array or an object that implements Countable in /home/customer/www/logansease.com/public_html/iparty/wp-content/themes/grizzly-theme/base/shortcodes/fix.php on line 36

In the last few months, facebook stopped supporting audio attachments in posts created through the facebook API. My app Quotables used this feature to post audio quotes from various movies on to the users wall. When Facebook stopped supporting this, it took a bit piece of functionality out of my app. After many hours of researching and trying and failing, I have at last figured out how to do this.

1- First you will need a web server that allows php scripts.
Download JW Player from here: http://www.longtailvideo.com/players/jw-flv-player/
This is a flash and html5 based video and music player.

2- You will need to create a php file that will contain the flash player in the same directory that you placed the jw player on your server. We’ll call this player.php.

<html> <head> <meta property="og:type" content="movie" /> <meta property="og:video:height" content="260" /> <meta property="og:video:width" content="420" /> <meta property="og:video:type" content="application/x-shockwave-flash" /> <meta property="og:title" content="<?php echo $_GET['title']; ?>" /> <meta property="og:description" content="<?php echo $_GET['desc']; ?>" /> <meta property="og:image" content="[path to a thumbnail].png" /> <meta property="og:video" content="[JW INSTALL PATH]/player.swf?file=<?php echo $_GET['file']; ?>"/> </head> <body> <h1>Quotables for iPhone and Android</h1> <h2>Hear and Share quotes for your favorite movies</h2> <h3><?php echo $_GET['title']; ?> </h3> <p><?php echo $_GET['desc']; ?> </p> <script type="text/javascript" src="jwplayer.js"></script> <div id="thePlayer"></div> <script type="text/javascript"> jwplayer("thePlayer").setup({ flashplayer: "player.swf", autostart: 'true', file: "<?php echo $_GET['file']; ?>", height: "270", width: "380" }); </script> </body> </html>

3- Now in our iOS app, we can call the graph API and point the post to JW Player

NSString * kJwPlayerPath = @"[http://your server path/player.swf?file=]" NSString * audioFileUrl = @"[http://path to a hosted/file.mp3]" NSString * quoteUrl = [NSString stringWithFormat:@"%@%@",kJwPlayerPath,audioFileUrl]; NSString * kVideoLinkBase = @"[http://yourserver path/player.php?]"; NSString * linkUrl = [NSString stringWithFormat:@"%@file=%@&title= %@&desc=%@",kVideoLinkBase,quote.audioFileUrl,@"title",@"description"]; NSMutableDictionary * dict = [NSMutableDictionary dictionary]; [dict setValue:@"Quotables: The Movie Quotes App." forKey:@"name"]; [dict setValue:linkUrl forKey:@"link"]; [dict setValue:quoteUrl forKey:@"source"]; [dict setValue:@"http://path.to/thumbnail.png" forKey:@"picture"]; [dict setValue:[NSString stringWithFormat:@"Audio Caption"] forKey:@"caption"]; [dict setValue:[NSString stringWithFormat:@"Audio Description"] forKey:@"description"]; [facebook dialog:@"feed" andParams:params andDelegate:self];

So, we are basically setting the source attribute to our swf file, passing in the audio file to play. We then set the link attribute to point to our new html5 php file, passing in the audio file, description and title.

The result is we can post audio to user’s facebook wall. People can listen to the audio right in facebook, including on an iPhone.

Comments

  Comments

  • 753195521
    6 / 12 / 2014

    how would one go about modifying this for an icecast or shoutcast radio stream?

    753195521 6 / 12 / 2014
  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    -->