My Tutorial: Using Facebook Connect w/ Cocos2d

Forums Programming high score, social and ads networks My Tutorial: Using Facebook Connect w/ Cocos2d

This topic contains 48 replies, has 27 voices, and was last updated by  idontchick 2 years, 7 months ago.

Viewing 25 posts - 1 through 25 (of 49 total)
Author Posts
Author Posts
December 12, 2009 at 3:43 pm #218816

Jeston
@rhapsodus

Greetings Cocos2d Community,

I wrote a tutorial after a lot of frustration finding information to let your game post to facebook users’ walls. Hopefully I don’t butcher the formatting on this post, but just in case I have the tutorial hosted on my webserver at http://www.loudgames.net/?p=17

So bear with me, I may have to edit this post a few times and I apologize in advance for that :)

========================

I have recently made a game on Iphone using Cocos2D that is Facebook Connect enabled. The app, when given permission by a Facebook user, has the capabilities of posting to the user’s profile pages. This feature set is very compelling for a developer to undertake as your game can post achievements, highscores, and various tidbits for everyone to see; and that makes the marketing team quite pleased.

What is less known is how this is accomplished and more importantly the code that drives it. I don’t pretend to do anything fancy with facebook’s API, but I did discover some unobvious quirks when I went through the process. I had a lot of terminology to sort through, and found that I was treading an undocumented path. In the end the results were nice: I had a login button, my app asked for correct permissions, and I was able to silently post to user’s walls without bothering the players.

So, I am writing this tutorial in hopes that others may benefit and save time. This tutorial isn’t a catch all and there are certainly a lot of facebook features to mull through, but at a minnimum I want to cover the process in hooking up facebook connect to a cocos2d made game with the ultimate goal of having the ability to post achievements to the web.

Step 0. Pre-reqs & getting the Facebook iphone SDK

Get it. Unzip it, and put the appropriate files into your code tree. I added a ‘Facebook’ grouping to my xcode project and included the entire /src/ subtree from the SDK at http://developers.facebook.com/connect.php?tab=iphone

Step 1. Rendering the Login/Logout buttons.

The first step is putting the login/logout buttons in. Everyone’s game architecture is different. To quickly describe mine I have:

1. Game Layer – I treat as the master of all logic

2. MenuLayer – Menu screen complete with a Play Button, Help, Facebook login buttons

3. Loading Screen, etc . . .

For my tutorial, I intend to have information about the real facebook status and various tidbits sent to my menu layer. The main concern here is that the menu layer manages the visual state of the login buttons: show 1 button when logged in, the other when I am logged out. This should be familiar territory to cocos2d developers and straight foward, creating the sprites, menus and setting up button callbacks. The code is as follows.

MenuLayer.h

//******************************************************
//Create two sprites for the facebook buttons
//******************************************************
MenuItemSprite* FaceBookButtonLogin;
MenuItemSprite* FaceBookButtonLogout;
Menu* FaceBookMenu;

//******************************************************
// Fired when the buttons get pushed
//******************************************************
-(void)FaceBookLoginPushed:(id)sender;
-(void)FaceBookLogoutPushed:(id)sender;

//******************************************************
// Status of our login, this will be 'told' to us from
// another layer, Yes this can probably be a property :)
//******************************************************
Boolean LoggedIn;
-(void)SetLoggedIn:(Boolean)status;

MenuLayer.m

//******************************************************
// Creation
//******************************************************
- (id) init
{
self = [super init];
if( self != nil )
{
LoggedIn = NO;

//******************************************************
// Images are provided in the bundle with connect sdk
//******************************************************
FaceBookButtonLogin = [MenuItemSprite itemFromNormalSprite:[Sprite spriteWithFile:@"FBConnect.bundle/images/login.png"] selectedSprite:nil disabledSprite:nil target:self selector:@selector(FaceBookLoginPushed:)];
FaceBookButtonLogout = [MenuItemSprite itemFromNormalSprite:[Sprite spriteWithFile:@"FBConnect.bundle/images/logout.png"] selectedSprite:nil disabledSprite:nil target:self selector:@selector(FaceBookLogoutPushed:)];

FaceBookMenu = [[Menu menuWithItems:FaceBookButtonLogout, FaceBookButtonLogin, nil] retain];
[self addChild:FaceBookMenu z:1];

//set positions and default states
[FaceBookButtonLogin setPosition:ccp(-1995, -215)];

[FaceBookButtonLogout setPosition:ccp(-1995, -215)];
}
return self;
}

// the rest is up to the game and how/when it shows the buttons, mine hides
// the buttons and turns them on when the menu layer is shown by the gamelayer
-(void)HideFaceBookButtons
{
[FaceBookButtonLogout setIsEnabled:NO];
[FaceBookButtonLogout setVisible:NO];
[FaceBookButtonLogin setIsEnabled:NO];
[FaceBookButtonLogin setVisible:NO];
[FaceBookButtonLogin setPosition:ccp(-1995, -215)];
[FaceBookButtonLogout setPosition:ccp(-1995, -215)];
}
-(void)ArrivedAtMenu
{
[self SetLoggedIn:LoggedIn];

//some animation, why not make it look nice?
[FaceBookButtonLogout setPosition:ccp(FaceBookButtonLogout.position.x - 200, FaceBookButtonLogout.position.y)];
[FaceBookButtonLogout runAction:[Sequence actions:[DelayTime actionWithDuration:0.8],[MoveBy actionWithDuration:0.3 position:ccp(220,0)],[MoveBy actionWithDuration:0.15 position:ccp(-20,0)],nil]];
[FaceBookButtonLogin setPosition:ccp(FaceBookButtonLogin.position.x - 200, FaceBookButtonLogin.position.y)];
[FaceBookButtonLogin runAction:[Sequence actions:[DelayTime actionWithDuration:0.8],[MoveBy actionWithDuration:0.3 position:ccp(220,0)],[MoveBy actionWithDuration:0.15 position:ccp(-20,0)],nil]];
}
//******************************************************
// Display appropriate button
//******************************************************
-(void)SetLoggedIn:(Boolean)status
{
LoggedIn = status;

[FaceBookButtonLogin setIsEnabled:YES];
[FaceBookButtonLogin setVisible:YES];
[FaceBookButtonLogout setIsEnabled:YES];
[FaceBookButtonLogout setVisible:YES];

if( LoggedIn )
{
[FaceBookButtonLogin setPosition:ccp(-1999,0)];
[FaceBookButtonLogout setPosition:ccp(-105, -215)];
}
else
{
[FaceBookButtonLogout setPosition:ccp(-1999,0)];
[FaceBookButtonLogin setPosition:ccp(-105, -215)];
}
}

//******************************************************
// And lastly, what to do when the buttons are pushed
// Lets defer the action to the owner of logic
//******************************************************
-(void)FaceBookLoginPushed: (id)sender
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"LoginFaceBook" object:nil];
}

-(void)FaceBookLogoutPushed: (id)sender
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"LogOutFaceBook" object:nil];
}

Step 2. Managing the Login state

In the last step we defferred the logic of the actual process of logging in to the GameLayer. Lets get to managing that now.

There are some pre-requisits to meet first, namely we must know about when a login occurs and fails. This is accomplished by registering our GameLayer with some notifications and delegates. After which, we will need to manage the session object. The session is important to be familiar with, it does all the actual communicating to the web and delegates the responses back to your app. In essence, this is our connection mule. With the following code we intend to keep track of this session, and put some ground work for our delegates.

GameLayer.h

#import "FBConnect/FBConnect.h"

//Register the delegates with this layer
@interface GameLayer : Layer
<FBDialogDelegate, FBSessionDelegate, FBRequestDelegate> {}

//******************************************************
// This is the facebook session that we use to interface
// with facebook, EVERYTHING facebook related relies
// on this: Login, Publishing Stories, etc...
//******************************************************
FBSession* _session;

//******************************************************
// Facebook notifications from MenuLayer to do the work
//******************************************************
-(void)LogOutFaceBook:(NSNotification *)notification;
-(void)LoginFaceBook:(NSNotification *)notification;

GameLayer.m

//******************************************************
// These two strings are required for all facebook apps,
// and you get them when you create an app on facebook,
// You can research what the key / secret is on your own
// but don't need covering here
//******************************************************
static NSString* kApiKey = @"XXXXXXXXXXXXXXXXXXXXXXXXXXX";
static NSString* kApiSecret = @"YYYYYYYYYYYYYYYYYYYYYYYYY";

//******************************************************
// Creation
// Now, we need to create the session, when and how you
// decide to do that is up to you. I have a message fired
// when my game is done loading, and that is when I decided
// to create my session. [See below]
//******************************************************
- (id) init
{
self = [super init];
if (self != nil)
{
_session = nil;
MainMenu = [[MenuLayer alloc] init];

[self.parent addChild:MainMenu z:51];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(LoginFaceBook:) name:@"LoginFaceBook" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(LogOutFaceBook:) name:@"LogOutFaceBook" object:nil]; }
return self;
}

//******************************************************
// Finished loading, create session and tell it to do its
// job with the Facebook api
//******************************************************
-(void)FinishedLoading
{
_session = [[FBSession sessionForApplication:kApiKey secret:kApiSecret delegate:self] retain];
[_session resume];
}
//************************************************************
// When logout is pushed, nothing fancy needs to happen; just
// call a facebook api logout on our session
//************************************************************
-(void)LogOutFaceBook:(NSNotification *)notification
{
if( _session != nil )
{
[_session logout];

}
}

//************************************************************
// When we push login, we display a facebook api dialog with our
// session, results will be sent to delegates ( coming up)
//************************************************************
-(void)LoginFaceBook:(NSNotification *)notification
{
FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:_session] autorelease];
[dialog show];
}

As you can see, there is a piece still missing. The session is created, we know what to do when the buttons get pushed and we have our notifications in place now, but where does the actual login take place? You can spend your time digging through the facebook docs but the short answer is the facebook delegates get fired. This is where we need to update our GameLayer and add all needed delegates. We can certainly add the code for our fail / success case of a login now though.

GameLayer.m addition

///////////////////////////////////////////////////////////////////////////////////////////////////
// FBDialogDelegate
- (void)dialog:(FBDialog*)dialog didFailWithError:(NSError*)error
{

}
///////////////////////////////////////////////////////////////////////////////////////////////////
// FBSessionDelegate
- (void)session:(FBSession*)session didLogin:(FBUID)uid
{
[MainMenu SetLoggedIn:YES];
}

- (void)sessionDidNotLogin:(FBSession*)session
{
[MainMenu SetLoggedIn:NO];
}

- (void)sessionDidLogout:(FBSession*)session
{
[MainMenu SetLoggedIn:NO];
}

//FYI:
//Called when the facebook login dialog button is pushed
- (void)dialogDidSucceed:(FBDialog*)dialog
{
}

//FYI:
//Called when the facebook login cancel button is pushed
- (void)dialogDidCancel:(FBDialog*)dialog
{

}

///////////////////////////////////////////////////////////////////////////////////////////////////
// FBRequestDelegate

- (void)request:(FBRequest*)request didLoad:(id)result
{
}

- (void)request:(FBRequest*)request didFailWithError:(NSError*)error
{
NSLog([NSString stringWithFormat:@"Error(%d) %@", error.code, error.localizedDescription]);
}

Either of two functions [didLogin or didNotLogin] The facebook APIs handle these cases for us, so that is a big bonus. They should be called relatively quickly after our call to resume on the session when its first created.

Step 4. Logged In but can we do anything? Permissions.

As dictated by Facebook, and assuming the user logged in correctly, we still can’t start making posts and publishing to the user’s wall. The last detail that remains is handling permissions. This means that the user has to still allow our game the right to publish. This is up to a designer on how to present then but this tutorial presents this scenario when the user logs in. We want to ask for permission to post things at the time of first login.

Tim Stephenson wrote a useful blog post about managing the permission state of a logged in user and did so in such an elegant way that I can’t honestly improve on it, so I followed his code as

posted on: http://www.raddonline.com/blogs/geek-journal/iphone-sdk-using-facebook-connect-for-iphone-working-with-extended-permissions-part-2-of-2/

I highly suggest reading his post if you want to know how it works. To make things shorter I will just show it and use it on blind faith.

PermissionStatus.h

#import <Foundation/Foundation.h>
#import "FBRequest.h"

@protocol PermissionStatusDelegate;

@interface PermissionStatus : NSObject <FBRequestDelegate> {
BOOL userHasPermission;
id<PermissionStatusDelegate> delegate;
}

@property (nonatomic, assign) BOOL userHasPermission;
@property (nonatomic, retain) id<PermissionStatusDelegate> delegate;

- (PermissionStatus *)initWithUserId:(long long int)uid;

@end

#pragma mark method to call after response
@protocol PermissionStatusDelegate <NSObject>
- (void)statusWasSet:(BOOL)status;
@end

PermissionStatus.m

#import "PermissionStatus.h"

@implementation PermissionStatus
@synthesize userHasPermission;
@synthesize delegate;

- (PermissionStatus *)initWithUserId:(long long int)uid {
self = [super init];

if (self) {
NSString* fql = [NSString stringWithFormat:
@"select status_update from permissions where uid == %lld", uid];
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
[[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
userHasPermission = NO;
}
return self;
}

#pragma mark FBRequestDelegate
- (void)request:(FBRequest*)request didLoad:(id)result {
NSArray *permissions = result;
NSDictionary *permission = [permissions objectAtIndex:0];
userHasPermission = [[permission objectForKey:@"status_update"] boolValue];
[delegate statusWasSet:userHasPermission];
}

@end

With this usefull class, we can go back to our logic layer and keep track of the permissions.

GameLayer.h

#import "PermissionStatus.h"

// Here we add another delegate to use Tim's permission status
@interface GameLayer : Layer
<FBDialogDelegate, FBSessionDelegate, FBRequestDelegate, PermissionStatusDelegate> {}

// Create a property to keep track of the status
PermissionStatus *permissionStatusForUser;
@property (nonatomic, retain) PermissionStatus *permissionStatusForUser;

GameLayer.m

@synthesize permissionStatusForUser;
- (id) init
{
//... Our previous code
permissionStatusForUser = nil;
}

//****************************************************************
//delegate as described in the permissions class
// The end result will have two outcomes
// Yes: Great, the user gave us permissions to post content
// so we dont need to do anything else!
// No: We should display and ask for permissions
//****************************************************************
- (void)statusWasSet:(BOOL)status
{
//Instantiate the PermissionStatus class with the user id.
if ( !permissionStatusForUser.userHasPermission )
{
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.permission = @"publish_stream";
[dialog show];
}
else
{

}
}
//*******************************************************************
// This time when our login occurs we will now see and ask for
// permission status
//*******************************************************************
- (void)session:(FBSession*)session didLogin:(FBUID)uid
{
//Instantiate the PermissionStatus class with the user id.
permissionStatusForUser = [[PermissionStatus alloc] initWithUserId:session.uid];
permissionStatusForUser.delegate = self;
[MainMenu SetLoggedIn:YES];
}

//*******************************************************************
// Our log out needs to change a little bit so we can track permissions
//*******************************************************************

-(void)LogOutFaceBook:(NSNotification *)notification
{
if( _session != nil )
{
[_session logout];
if( permissionStatusForUser != nil )
{
[permissionStatusForUser dealloc];
permissionStatusForUser = nil;
}
}
}

Now things are looking up. We have login status being tracked and we know if our app has permissions to post

Step 5. Posting Content

Now we get to make use of our hard work thus far. At this point, the user will be playing our game and perhaps achieved a high score or completed some great achievement. This would be a good place to fire off and automatically make a post to their Facebook wall. Many games choose to do this at their discretion and some will even create different dialogs. The intent of this article was to show how to make a wall post, and this game will just silently post without bothering the user. The facebook sdk has many methods and options of posting content and I will leave it up to you to go dig those methods up and learn your options. To finish our original goal we n

GameLayer.h

//******************************************************
// Facebook stream publishing functions
//******************************************************
-(void)postFaceBookStory:(NSString*)text:(NSString*)imgUrl;

GameLayer.m

//******************************************************
// Facebook stream publishing functions
//******************************************************
-(void)postFaceBookStory:(NSString*)text:(NSString*)imgUrl
{
//Check to see if the user is letting us make the post
if( permissionStatusForUser != nil && permissionStatusForUser.userHasPermission )
{
//Set up the json encoded message as defined by Facebook SDK
NSMutableDictionary *FeedStoryParams = [[[NSMutableDictionary alloc] init] autorelease];
[FeedStoryParams setObject:@"1.0" forKey:@"v"];
[FeedStoryParams setObject:text forKey:@"message"];

// all of my facebook achievement images are 200, 200
NSString *attachment = [NSString stringWithFormat:@"{"media": [{"type": "image", "src": "<a>%@</a>", "href": "<a href="http://apps.facebook.com/YOURAPP//">http://apps.facebook.com/YOURAPP/</a>", "width":"200","height":"200" }]}", imgUrl];
[FeedStoryParams setObject:attachment forKey:@"attachment"];
[[FBRequest requestWithDelegate:self] call:@"facebook.stream.publish" params:FeedStoryParams];
}
}

And finally, making the appropriate call to post the story:

strwhich = [NSString stringWithFormat:@"Achievement: My Game Posted on Facebook"];

[self postFaceBookStory:[NSString stringWithFormat:@"played a game that I gave permissions to post to my wall"]:[NSString stringWithFormat:@"<a href="http://www.someurl.com/some_image.jpg">http://www.someurl.com/some_image.jpg</a>"]];

That should be it! I hope to see some posts on facebook from some cocos2d games now !

~Jeston Furqueron~

December 14, 2009 at 2:11 am #268183

goldplated
@goldplated

Thanks for sharing this info!!!

December 14, 2009 at 2:17 am #268184

redsky
Participant
@redsky

thanks for taking the time to write this up! since you made it so easy for me i may have no excuse to not hook it up.

December 14, 2009 at 4:18 pm #268185

onedayitwillmake
Participant
@onedayitwillmake

This is great, i really hate how openfeint looks, that slick black look is out so out of place for so many games!

For my next game, now i know there’s a better option that won’t be a pain to implement.

December 14, 2009 at 6:11 pm #268186

ripp
@ripp

@jeston, thanks for posting this! I started my monday with the intention of scouring the internet for FBConnect info for my next app. Good thing I check the forum first thing in the morning, you saved me a ton of time.

December 16, 2009 at 1:54 am #268187

klicktock
@klicktock

Thanks again for this. Implemented!

I’m not a fan of OpenFeint, etc. It’s a pain to connect to friends – I only have 1 :(

I wish that Facebook Connect allowed storing of scores/app info on their servers though. Definitely quite a bit more work to get going that Agon.

December 18, 2009 at 3:22 pm #268188

shazbox
@shazbox

Hmm, I should have wrote something like this a few months ago.

The Facebook team definitely drove me insane when I was trying to add FBConnect.

December 18, 2009 at 6:36 pm #268189

Matt Rix
@mattrix

I just did this for an app at work, and there are a couple more things to know:

- Facebook’s own SVN repo is OUT OF DATE. Do not use it, it’s old code. Get the code from this Github repo instead: http://github.com/facebook/facebook-iphone-sdk

- A lot of tutorials will tell you to use feed templates, but those are about to be deprecated. You should now be using Stream.publish, which means you’ll need to get publish_stream permission. That’s why the new FBConnect code has FBStreamDialog, not just FBFeedDialog(the old one).

- The FBStreamDialog has all kinds of cool things you can do with attachments and action links. You can attach images, mp3s, and swfs among other things. Check this out to see what you can do: http://wiki.developers.facebook.com/index.php/Attachment_(Streams)

- The FBStreamDialog will return SUCCESS even if the user cancels publishing the message. This is a bug in FBConnect’s code, and it’s really annoying… but hopefully they’ll fix it it soon.

- Stream attachments use a JSON style syntax, but in most of Facebook’s samples they use single quotes. Single quoted JSON doesn’t work with FBConnect on the iPhone. You’ll need to use escaped double quotes, like this:

FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.userMessagePrompt = @"Example prompt";
dialog.attachment = @"{"name":"Facebook Connect for iPhone","href":"http://developers.facebook.com/connect.php?tab=iphone","caption":"Caption","description":"Description","media":[{"type":"image","src":"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg","href":"http://developers.facebook.com/connect.php?tab=iphone/"}],"properties":{"another link":{"text":"Facebook home page","href":"http://www.facebook.com"}}}";
[dialog show];

December 23, 2009 at 1:27 am #268190

SPlogG
@splogg

When should ‘FinishedLoading’ get called?

December 23, 2009 at 2:11 am #268191

mobilebros
Moderator
@mobilebros

I think this post might be a good candidate for the tips page, I’ll add a link to it.

December 23, 2009 at 4:10 am #268192

SPlogG
@splogg

Got all the code in, everything compiles & links. But, no menu items show up on the screen, traced the code thru and it never gets to the ‘draw()’ in ‘CCMenuItem.cpp’, anyone had this problem?

December 24, 2009 at 4:39 am #268193

SPlogG
@splogg

User error.

December 25, 2009 at 11:02 am #268194

vanillasky65
@vanillasky65

Thanks! Should be really useful.

February 20, 2010 at 4:05 am #268195

zxl777
@zxl777

iPhone could not upload picture by using Facebook SDK after 2009-2-17, Why?

March 18, 2010 at 1:05 am #268196

Webtopia
Participant
@webtopia

Hi,

Thanks heaps for adding this tutorial. I’m looking into implementing it now and this should give me a great head start.

One thing that keeps getting skipped over in the facebook tutorials and documentation is the facebook developer side of things.

I have no intention of creating an actual facebook application just my iphone app using cocos2d. I assume you are the same.

1. Do you just create what is a essentially a dummy application in facebook to receive your API Key and Secret?

2. Do you need to add images and some sort of functioning application into facebook?

3. Does it need to be approved?

4. Do I need to do something else in the facebook developer section to set up streams?

or

Is the API Key and Secret all I need to get feeds/streams published to facebook users News Feed?

Thanks,

Travis

March 18, 2010 at 1:22 am #268197

Matt Rix
@mattrix

1. Yeah you have to create a dummy application

2. The application doesn’t NEED to function, but it probably shouldn’t be left blank. Just put your game’s logo and maybe a link to your site or some info about the game. Nothing fancy, but not nothing :)

3. No, it doesn’t need to be approved.

4. No, all you need is the api key + secret.

March 18, 2010 at 1:23 am #268198

Webtopia
Participant
@webtopia

Cheers

March 18, 2010 at 6:42 am #268199

Matt Rix
@mattrix

Grr, Facebook still hasn’t fixed this error that I mentioned here 2 months ago: “The FBStreamDialog will return SUCCESS even if the user cancels publishing the message. This is a bug in FBConnect’s code, and it’s really annoying… but hopefully they’ll fix it it soon.”

Time to file another bug report.

March 18, 2010 at 8:22 am #268200

randomtruth
@randomtruth

@Matt

From what Ive seen the Facebook Developers don’t care at all about Facebook Connect for Native Applications. The last five bug reports Ive seen (all for pretty major bugs btw) have gotten responses from the Facebook Developers stating something along the lines of “Its a feature, not a bug”.

Here’s one right off the top of my head.

http://bugs.developers.facebook.com/show_bug.cgi?id=8667

March 24, 2010 at 1:16 am #268201

Matt Rix
@mattrix

Yep, you’re totally right. Luckily some guy figured out how to get around Facebook’s *intentional* bug (the one I was mentioning): http://j.mp/9aJbKJ

Basically, Facebook doesn’t want you to know whether the user was successful or not(!), because they’re afraid you’ll give them incentives for sharing things with their friends (ie. “you’ll get 100xp if you share this with your friends”). I appreciate how they’re trying to protect the user, but I *strongly* disagree with their way of doing it(especially since it’s so easy to work around).

March 26, 2010 at 2:10 am #268202

Webtopia
Participant
@webtopia

Not sure if I’m doing things correctly but the facebook login page looks like a standard web-browser.

I noticed in FBLoginDialog.m they direct you to

static NSString* kLoginURL = @”http://www.facebook.com/login.php”;

I’ve changed mine to

static NSString* kLoginURL = @”http://touch.facebook.com/login.php”;

Doesn’t it make more sense?

March 26, 2010 at 4:01 am #268203

Webtopia
Participant
@webtopia

Sorry ignore that last post. I was being an idiot. I hadn’t created the session so it wasn’t working properly.

It needs to stay as http://www.facebook.com or it will not work.

March 28, 2010 at 1:02 pm #268204

Webtopia
Participant
@webtopia

Hi Everyone,

OK I’ve got it working pretty good now.

Just a couple of questions about the FBStreamDialog.

I understand it doesn’t have the full functionality on the iPhone as it does in facebook apps.

If I have the line

dialog.userMessagePrompt = @"User Message";

Can I prefill the message with something like “has scored 4 out of 20 playing” so the user can change the message if he/she likes but if they don’t the first line appearing on their facebook wall would be.

John Smith has scored 4 out of 20 playing

Then in the next line I could

dialog.attachment = @"{"name":"iPhoneAppName - iPhone App","href":"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=XXXXXXXX&mt=8"}

so it shows up as a link to the iphone app with the title of the app.

Alternatively if I can’t prefill the messagePrompt is there some way to reference the facebook username with a variable. So that I can create a “John Smith has scored…” style output in the dialog.attachment section or the wall post.

What other variables are there that I can use. Is this the complete list? http://wiki.developers.facebook.com/index.php/Attachment_%28Streams%29

Thanks,

Travis

June 15, 2010 at 9:11 am #268205

hinata88
@hinata88

Hi all, i try to implemented the codes… but these lines are simply produce error because the “” and //

NSString *attachment = [NSString stringWithFormat:@"{"media": [{"type": "image", "src": "%@", "href": "http://apps.facebook.com/YOURAPP/", "width":"200","height":"200" }]}”, imgUrl];

[self postFaceBookStory:[NSString stringWithFormat:@"played a game that I gave permissions to post to my wall"]:[NSString stringWithFormat:@"http://www.someurl.com/some_image.jpg"]];

Help anyone?…. thanks in advance…

August 26, 2010 at 2:34 pm #268206

ZebulonSwe
@zebulonswe

Hi all, i try to implemented the codes… but these lines are simply produce error because the “” and //

NSString *attachment = [NSString stringWithFormat:@"{"media": [{"type": "image", "src": "%@", "href": "http://apps.facebook.com/YOURAPP/", "width":"200","height":"200" }]}”, imgUrl];

[self postFaceBookStory:[NSString stringWithFormat:@"played a game that I gave permissions to post to my wall"]:[NSString stringWithFormat:@"http://www.someurl.com/some_image.jpg"]];

Help anyone?…. thanks in advance…

I have the exact same problem… :(

Viewing 25 posts - 1 through 25 (of 49 total)

You must be logged in to reply to this topic.