0

I want to get the app user ID for Facebook, as described here: https://developers.facebook.com/docs/ads-for-apps/custom-audiences-for-mobile-apps/

The code snippet they give is:

[FBRequestConnection startForCustomAudienceThirdPartyID:nil
    completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
      NSString *id = error ? nil : [result objectForKey:@"custom_audience_third_party_id"];
      // Stash off this id, send it to your server, etc.  Use later to construct
      // a custom audience.  A result of 'nil' means that either the user can't be
      // identified, or they've limited ad tracking via iOS 6.
    }
];

This always returns error 400 for me. Answers like this suggest that it needs to be used as part of a larger piece of code but there's no mention of this on the Facebook page.

Can I just use the snippet above, or do I need to implement something around it?

Community
  • 1
  • 1
parsley72
  • 8,449
  • 8
  • 65
  • 98

2 Answers2

1

I got this from the FB developer page:

Discussion: This method will thrown an exception if either <[FBSettings defaultAppID]> or <[FBSettings clientToken]> are nil. The appID won't be nil when the pList includes the appID, or if it's explicitly set. The clientToken needs to be set via <[FBSettings setClientToken:]>.

.....

Please check the conditions above first. Ass per documentation

startForCustomAudienceThirdPartyID:    -> should actually point to the current FBSession   
Paulo
  • 1,245
  • 10
  • 8
  • I'm not seeing an exception, it just returns error 400. I tried calling [FBSettings setClientToken:XXXX] but it didn't make any difference. – parsley72 Feb 17 '14 at 21:44
  • 400 is an HTML exception code. You should check out if your FB appID is properly configured .... It should be in the info.plist / Custom IOS Properties. also in your app delegate should have something like this : -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { BOOL ret = [FBSession.activeSession handleOpenURL:url]; – Paulo Feb 19 '14 at 01:21
  • .... If you have a standalone app you need the AppID which you get by creating an app via the FB developer page there is some sort of validation with your IOS bundle id which Facebook requires for you to register your IOS app. If I am not mistaken the client token is required for Oauth applications where your users login to your app using their Facebook credentials - the token refers to an active FB session. – Paulo Feb 19 '14 at 05:14
  • So the answer to my question "Can I just use the snippet above" is "No, your user needs to login to Facebook". That's what I was looking for. – parsley72 Feb 19 '14 at 09:47
  • Yes, If that is what your app is supposed to do. – Paulo Feb 19 '14 at 22:08
  • Yes, If that is what your app is supposed to do. But if done properly, the app should automatically be switching to Facebook and asking the user to login (the FB sample login routines in the SDK will do this in a previous call). – Paulo Feb 19 '14 at 22:16
0

Right after the session is created do this: [FBSession setActiveSession:session];

Answered here: Facebook iOS SDK 3.1: "Error: HTTP status code: 400"

Community
  • 1
  • 1
Gaurav Joseph
  • 927
  • 14
  • 25