I have come to you guys in the past with problems and you guys helped me when I needed it the most. Now I once again come to you with a problem, but this problem involves the Facebook SDK and its integration with my iPhone app.
Here is what I want to do:
I want to retrieve the user of my app's Facebook friends and their friends' profile pictures. I then want to display both the name and profile picture of those people in a random way, but do to download speed and people having a ton of friends, I only want to download 10 friends at a time. I have already started, trying to implement Facebook into my app, and I am not getting that far. I have been able to have the user authenticate with Facebook, but can't really go farther than that.
I am posting parts of my files below in the hopes that someone can spot where i am messing up.
One of the problems that I have encountered so far, is that in my AppDelegate.m, my NSLog of "getFacebookStuff mentioned" does get outputted to my log, however, the NSLog that I have in the getFacebookStuff method, located in my Game class, does not get outputted.
This is what my program outputs in the logs when it runs:
Code:
2012-02-01 11:45:52.852 AppName[11091:f803] Getting permissions
2012-02-01 11:45:52.853 AppName[11091:f803] Reached end of start setup
2012-02-01 11:45:58.280 AppName[11091:f803] fbDidLogin finished
2012-02-01 11:45:58.281 AppName[11091:f803] getFacebookStuff called
2012-02-01 11:45:58.282 AppName[11091:f803] Reached facebook request for stuff and end of start method
2012-02-01 11:45:58.282 AppName[11091:f803] getFacebookStuff mentioned
Terminating in response to SpringBoard's termination.
Program ended with exit code: 0
Any help at all would be very much appreciated! I have looked online at multiple sources but none of them have given me an answer.
The problem is, I think, that you are creating to Facebook objects.
One in your didFinishLaunchingWithOptions function and one in Game.m viewDidLoad function.
As I see it, the one gets authorized and the other not so you can't download your users friends.
What you can do is either use a singleton which will hold the Facebook object so that it is accessible everywhere in your app, which is the best option in my opinion,
or just use the Facebook object which you initialize in your AppDelegate,
or pass the Facebook object to the Game view controller through the facebook property you have declared.
For the first option I would suggest, if you don't already know how to use singletons, to look up DuncanC's tutorial in this forum.
For the second option get rid of the Facebook property and instance variable in Game.h and use appDelegate.facebook
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//FACEBOOK
facebook = [[Facebook alloc] initWithAppId:@"164730030304096" andDelegate:self];
//This is overkill. You are already in the AppDelegate. There is no need to reference it again. Delete those two lines they are unnecessary
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.facebook = facebook;
__________________ SQLed - Your Database Manager on the go
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//FACEBOOK
facebook = [[Facebook alloc] initWithAppId:@"164730030304096" andDelegate:self];
//This is overkill. You are already in the AppDelegate. There is no need to reference it again. Delete those two lines they are unnecessary
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.facebook = facebook;
Thanks for all the help so far apatsufas, but do you know how I can limit the number of friends that it downloads? Can i only have it download ten friends at a time?
Also, I edited somethings to make the facebook authenticate on a certain view, but now I get some weird errors :
Code:
2012-02-01 15:23:01.376 AppName[11465:f803] Getting permissions
2012-02-01 15:23:01.377 AppName[11465:f803] Reached end of start setup
2012-02-01 15:23:06.660 AppName[11465:f803] fbDidLogin finished
2012-02-01 15:23:06.660 AppName[11465:f803] getFacebookStuff called
2012-02-01 15:23:06.664 AppName[11465:f803] Reached facebook request for stuff and end of start method
2012-02-01 15:23:06.664 AppName[11465:f803] getFacebookStuff mentioned
2012-02-01 15:23:08.250 AppName[11465:f803] received response
2012-02-01 15:23:08.562 AppName[11465:f803] reached request method
2012-02-01 15:23:08.563 AppName[11465:f803] class of request : FBRequest
2012-02-01 15:23:08.564 AppName[11465:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
Here is what I have in my request method that I believe the error is being thrown on:
for every key before adding the objects to your arrays.
So I did exactly as you said to do, and it is still not working...
Here is what the console says:
Code:
2012-02-02 14:25:34.237 AppName[13020:f803] Getting permissions
2012-02-02 14:25:34.238 AppName[13020:f803] Reached end of start setup
2012-02-02 14:25:39.470 AppName[13020:f803] fbDidLogin finished
2012-02-02 14:25:39.471 AppName[13020:f803] getFacebookStuff called
2012-02-02 14:25:39.474 AppName[13020:f803] Reached facebook request for stuff and end of start method
2012-02-02 14:25:39.475 AppName[13020:f803] getFacebookStuff mentioned
2012-02-02 14:25:40.785 AppName[13020:f803] received response
2012-02-02 14:25:40.974 AppName[13020:f803] reached request method
2012-02-02 14:25:40.974 AppName[13020:f803] class of request : FBRequest
2012-02-02 14:25:40.975 AppName[13020:f803] Request failed for some reason
Terminating in response to SpringBoard's termination.
Program ended with exit code: 0
Here is the code in my Game.m file where the error is:
So I did exactly as you said to do, and it is still not working...
Here is what the console says:
Code:
2012-02-02 14:25:34.237 AppName[13020:f803] Getting permissions
2012-02-02 14:25:34.238 AppName[13020:f803] Reached end of start setup
2012-02-02 14:25:39.470 AppName[13020:f803] fbDidLogin finished
2012-02-02 14:25:39.471 AppName[13020:f803] getFacebookStuff called
2012-02-02 14:25:39.474 AppName[13020:f803] Reached facebook request for stuff and end of start method
2012-02-02 14:25:39.475 AppName[13020:f803] getFacebookStuff mentioned
2012-02-02 14:25:40.785 AppName[13020:f803] received response
2012-02-02 14:25:40.974 AppName[13020:f803] reached request method
2012-02-02 14:25:40.974 AppName[13020:f803] class of request : FBRequest
2012-02-02 14:25:40.975 AppName[13020:f803] Request failed for some reason
Terminating in response to SpringBoard's termination.
Program ended with exit code: 0
Here is the code in my Game.m file where the error is:
So i discovered what the problem was. When i was making the request over to Facebook, I was only asking for "me/friends" when I needed a more specific parameter to ask for which is "me/friends?access_token=[oauth_token]&fields=name,id,picture,gender"
Thanks for all your help apatsufas, I really appreciate it!
P.S. I am still stuck on how to limit the number of friends that it downloads per request.