How to create Facebook test users programmatically using Facebook iOS SDK 3.14.1

791 Views Asked by At

We are trying to create Facebook test users using the Facebook iOS SDK 3.14.1 according to their website: https://developers.facebook.com/docs/graph-api/reference/v2.0/app/accounts/test-users

Here is our code:

NSString *fbAccessToken = [NSString stringWithFormat:@"%@",FBSession.activeSession.accessTokenData];

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                        @"true", @"installed",
                        fbAccessToken, @"owner_access_token",
                        nil
                        ];



NSString *path = [NSString stringWithFormat:@"/%@/accounts/test-users", kFacebookID];

/* make the API call */
[FBRequestConnection startWithGraphPath:path        ///{app-id}/accounts/test-users"
                             parameters:nil
                             HTTPMethod:@"POST"
                      completionHandler:^(
                                          FBRequestConnection *connection,
                                          id result,
                                          NSError *error
                                          )
                      {

                          if (result  && !error)
                          {
                              NSLog(@"Test-User created successfully: %@", result);
                          }
                          else
                          {
                              NSLog(@"Error creating test-user: %@", error);
                              NSLog(@"Result Error: %@", result);
                          }

                      }];

When we run it we receive the following error:

    error =         {
        code = 15;
        message = "(#15) This method must be called with an app access_token.";
        type = OAuthException;
    };

We have also tried without the parameter owner_access_token but the same error occurs. How can we create Facebook Test users programmatically using the Facebook iOS SDK?

1

There are 1 best solutions below

0
On

Solution:

Instead of using the active session access token in you should use the App Token. Just replace FBSession.activeSession.accessTokenData with your App Token.

The App Token can be found here: https://developers.facebook.com/tools/accesstoken/

As per WizKid comment above, this is for testing purposes only.