FBConnect and Three20

23 views
Skip to first unread message

RobAMacAF

unread,
Nov 17, 2010, 10:44:37 AM11/17/10
to Three20
I am using FBConnect to connect to the users info. I am using the
default API for FBConnect. I have it so it opens the page and asks for
my information. But then it is supposed to pass this info back to my
app and it doesn't. I believe the problem lies here:

In the FBConnect demo app, in the delegate they have this:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL
*)url {
return [[controller facebook] handleOpenURL:url];
}

But in three20 we use this:

- (BOOL)application:(UIApplication*)application handleOpenURL:
(NSURL*)URL {
[[TTNavigator navigator] openURLAction:[TTURLAction
actionWithURLPath:URL.absoluteString]];
return YES;
}

Therefore the methods in the FBConnect, such as:
- (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse
*)response {
NSLog(@"received response");
};

and

- (void)request:(FBRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"%@", [error localizedDescription]);
};

aren't getting called.

Any idea on how to make this work? I am THIS close to figuring it out
but have been scratching my head all morning. I even looked at the FB
demo app in three20 but it doesn't deal with logging in, etc.

Thanks
Rob


Brett Spurrier

unread,
Nov 17, 2010, 10:58:47 AM11/17/10
to thr...@googlegroups.com
Hi Rob,

I had the same problem. Here is how I got around it...might not be
ideal, but it worked for me.

So the latest FBConnect-iOS has an option to take the login
credentials from (i) the native FB app session, (ii) a logged in
session of FB via Safari, or (iii) a UIWebView based dialog window.
The defaults are (i) and (ii), which both require the code:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
       return [[controller facebook] handleOpenURL:url];
}

as you pointed out. However, you can force the dialog ( option (iii) )
to appear in your app, if you modify Facebook.m:

From:
[self authorizeWithFBAppAuth:YES safariAuth:YES];

To:
[self authorizeWithFBAppAuth:NO safariAuth:NO];

This completely bypasses the need for


- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {}

and Three20 is able to use the function as it does.

Hope this helps.

Cheers,
Brett

> --
> You received this message because you are subscribed to the Google
> Groups "Three20" group.
> To post to this group, send email to thr...@googlegroups.com
> To unsubscribe from this group, send email to
> three20+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/three20?hl=en
>
> To learn more about Three20, check out
> http://Three20.info/
>

Rob McClellan

unread,
Nov 17, 2010, 11:03:45 AM11/17/10
to thr...@googlegroups.com
That is perfect! Thank you

Sent from my iPhone

Brett Spurrier

unread,
Nov 17, 2010, 11:13:59 AM11/17/10
to thr...@googlegroups.com
No problem. I literally just figured that out the other day, so if you
run into any more snags, let me know and I'll see if I can help ya
out.

-Brett

On Wed, Nov 17, 2010 at 8:03 AM, Rob McClellan <roba...@gmail.com> wrote:
> That is perfect! Thank you
>
> Sent from my iPhone
>
> On Nov 17, 2010, at 10:59 AM, Brett Spurrier <brett.s...@gmail.com> wrote:
>
>> Hi Rob,
>>

>> I had the same problem. Here is how I got around it...might not beNo pro

Rob McClellan

unread,
Nov 17, 2010, 11:18:34 AM11/17/10
to thr...@googlegroups.com
One more question. Now that I have it logging in what is the best way
to get the user Id, info, etc.

Would
[_facebook requestWithGraphPath:@"me" andDelegage:self];
work?

Sent from my iPhone

Brett Spurrier

unread,
Nov 17, 2010, 11:31:45 AM11/17/10
to thr...@googlegroups.com
Hey Rob,

I'm pretty sure that would work, yes.

However, I am more adept at using ASIHTTPRequest for my web calls, so
I used the following code. Plus this is more extensible for all the
Graph API calls...just change the url to the appropriate Graph url.

//Post login called from the FB Connect delegate methods
- (void)fbDidLogin {
fbAccessToken = [_facebook accessToken]; //iVar
[self requestFacebookNameWithGraphAPI:fbAccessToken];
}

-(void)requestFacebookNameWithGraphAPI:(NSString *)token {

NSString *urlString = [NSString
stringWithFormat:@"https://graph.facebook.com/me?access_token=%@",
[token
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

//Call thr Facebook Graph API to grab the profile information
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDidFinishSelector:@selector(getFacebookProfileFinished:)];
[request setDelegate:self];
[request startAsynchronous];
}

- (void)getFacebookProfileFinished:(ASIHTTPRequest *)request {

//Grab the relevant FB information
NSString *responseString = [request responseString];

NSMutableDictionary *responseJSON = [responseString JSONValue];
[fbProfileDictionary setObject:[responseJSON
objectForKey:@"first_name"] forKey:@"FirstName"];
[fbProfileDictionary setObject:[responseJSON
objectForKey:@"last_name"] forKey:@"LastName"];

//Whatever else you want to grab
}

Make sure to retain the access_token somewhere. That way the user (a)
won't have to login past the first time, and (b) you can make any
graph call at any point.

Cheers,
Brett

PEZ

unread,
Nov 22, 2010, 2:27:11 AM11/22/10
to Three20
I had similar challenges, where I want to use three20 table views and
all. I ended patching FBConnect some to allow me to use it as a
factory for creating URLs that I can use with TTURLRequest. Usage
becomes something like so:

FBRequest* fbRequest = [fb getRequestWithGraphPath:@"me/home"
andDelegate:nil];
TTURLRequest* request = [TTURLRequest
requestWithURL: [fbRequest getConnectURL]
delegate: self];
...
[request send];

I've put my changes in this fork: https://github.com/PEZ/facebook-ios-sdk
I've also submitted a pull request: https://github.com/facebook/facebook-ios-sdk/pull/128
in the hopes that we'll see something similar supported by the
FBConnect soon. Please put your support behind this pull request if
you agree with me. Looks like users of APIHTTPRequest would benefit
from the same interface.

/PEZ
> > On Nov 17, 2010, at 11:14 AM, Brett Spurrier <brett.spurr...@gmail.com> wrote:
>
> >> No problem. I literally just figured that out the other day, so if you
> >> run into any more snags, let me know and I'll see if I can help ya
> >> out.
>
> >> -Brett
>
> >> On Wed, Nov 17, 2010 at 8:03 AM, Rob McClellan <robama...@gmail.com> wrote:
> >>> That is perfect! Thank you
>
> >>> Sent from my iPhone
>
> >>> On Nov 17, 2010, at 10:59 AM, Brett Spurrier <brett.spurr...@gmail.com> wrote:
>
> >>>> Hi Rob,
>
> >>>> I had the same problem. Here is how I got around it...might not beNo pro
> >>>> ideal, but it worked for me.
>
> >>>> So the latest FBConnect-iOS has an option to take the login
> >>>> credentials from (i) the native FB app session, (ii) a logged in
> >>>> session of FB via Safari, or (iii) a UIWebView based dialog window.
> >>>> The defaults are (i) and (ii), which both require the code:
>
> >>>> - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
> >>>>        return [[controller facebook] handleOpenURL:url];
> >>>> }
>
> >>>> as you pointed out. However, you can force the dialog ( option (iii) )
> >>>> to appear in your app, if you modify Facebook.m:
>
> >>>> From:
> >>>> [self authorizeWithFBAppAuth:YES safariAuth:YES];
>
> >>>> To:
> >>>> [self authorizeWithFBAppAuth:NO safariAuth:NO];
>
> >>>> This completely bypasses the need for
> >>>> - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {}
>
> >>>> and Three20 is able to use the function as it does.
>
> >>>> Hope this helps.
>
> >>>> Cheers,
> >>>> Brett
>
Reply all
Reply to author
Forward
0 new messages