5

I'm working on a music player for iPhone and I'd like users to be able to post songs to their Timelines. I have Facebook Connect working and I've registered Open Graph objects and actions with Facebook, but I can't figure out how to create/post an object and action from iOS.

Facebook gives me the following code, but I don't know where to use it for their iOS SDK.

<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# MYAPPNAME: http://ogp.me/ns/fb/MYAPPNAME#">
<meta property="fb:app_id"      content="xxxxxxxxxxxxxxx" /> 
<meta property="og:type"        content="MYAPPNAME:song" /> 
<meta property="og:url"         content="Put Your Own URL Here" /> 
<meta property="og:title"       content="Some Arbitrary String" /> 
<meta property="og:description" content="Some Arbitrary String" /> 
<meta property="og:image"       content="http://ogp.me/logo.png" /> 
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
Ryan
  • 3,853
  • 4
  • 28
  • 32

4 Answers4

3

You don't publish Objects from the iOS SDK - you publish Actions via the SDK and reference a URL to an object.

You do something similar to:

[[delegate facebook] requestWithGraphPath:@"me/YOUR_APP_NAMESPACE:YOUR_ACTION_NAME" andParams:[@"YOUR_OBJECT_URL" forKey:@"recipe"] andHttpMethod:@"POST" andDelegate:self];

Baically, you POST to the Graph API using the standard iOS Graph API Methods.

Theres a sample app which shows you how to do this here: https://github.com/facebook/wishlist-mobile-sample

Simon Cross
  • 13,315
  • 3
  • 32
  • 26
0

As far as I understand (and I hope I am/wish I were wrong), you cannot publish to Facebook's OpenGraph from an iOS 5.x native app directly. You need a more complex technology stack.

What Simon Cross and Nick are explaining is that you need a web server to receive your iOS actions, and your web server then communicates with Facebook. What's more, your web server (I believe) must actually host your objects - e.g. images, or songs in your case - and although there are great file-hosting services that interact very well with iOS (I've been digging Parse.com), they do not offer native/GUI-driven services for Facebook's OpenGraph. (I wish Heroku or Parse or someone offered something that would work and scale out-of-the-box..)

So, basically, you've got to roll your own web server to post to FB from a native app using OpenGraph.

NOTE: In iOS 6, it looks like the FB integration is just as slick and easy as the Twitter integration in iOS 5 (i.e. you'll be up and running in 30 minutes). I'll be messing around with it next week to see if that's the case. :)

toblerpwn
  • 5,415
  • 8
  • 38
  • 46
0

Just like Simon said, you don't publish 'OG Objects', you create/register them (along with your 'Actions' within the FB app dashboard). Then from your within your app you publish 'Actions' using the Facebook Object API. Your 'Actions' should include a reference (via a URL) to the instance of the custom OG Object you created. This custom OG object will have the unique data (e.g. title, data, etc).

Here is the kicker, those 'custom' OG objects HAVE TO, MUST, reside as a unique webpage that is hosted on a backend server. Sucks right!!! So you will either need to whip up backend server code to help you server up dynamically generated webpages (OG Objects) OR you hit up a service that will do it for you (BaaS -- backend as a service).

Although, FB says 'Parse' will handle this and that they are a partner, I couldn't find any information on Parse.com to do this.... in fact, I found support advice to be the contrary. Parse seems to be great for user management and cloud data storage for apps. But, I would recommend 'Kinvey', as they do support OG Object creation and storage (free for light traffic) and are simple to setup and integrate.

Muad'Dib
  • 511
  • 4
  • 11
0

You can not post songs directly, you'll need to host the songs on your own server (or a social network such as Soundcloud), then post those objects to Facebook. You can create objects on the fly though with the recent changes in the SDK using:

NSMutableDictionary<FBOpenGraphObject> *object =
            [FBGraphObject openGraphObjectForPostWithType:@"yourns:yourtype"
                                                    title:title
                                                    image:imageDataIfAny
                                                      url:@"a URL that can be clicked"
                                              description:descriptionIfAny];
            //attach custom data
            object[@"data"] = @{
                               //any custom data of your object type comes here
                                };

You don't need to put the OG tags to a webpage explicitly anymore, but you still need an URL parameter that will take the user to a webpage when clicked.

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389