FBSDKTestUsersManager.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  2. //
  3. // You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  4. // copy, modify, and distribute this software in source code or binary form for use
  5. // in connection with the web services and APIs provided by Facebook.
  6. //
  7. // As with any software that integrates with the Facebook platform, your use of
  8. // this software is subject to the Facebook Developer Principles and Policies
  9. // [http://developers.facebook.com/policy/]. This copyright notice shall be
  10. // included in all copies or substantial portions of the software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. #import <Foundation/Foundation.h>
  19. @class FBSDKAccessToken;
  20. /**
  21. Callback block for returning an array of FBSDKAccessToken instances (and possibly `NSNull` instances); or an error.
  22. */
  23. typedef void (^FBSDKTestUsersManagerRetrieveTestAccountTokensHandler)(NSArray *tokens, NSError *error) ;
  24. /**
  25. Callback block for removing a test user.
  26. */
  27. typedef void (^FBSDKTestUsersManagerRemoveTestAccountHandler)(NSError *error) ;
  28. /**
  29. Provides methods for managing test accounts for testing Facebook integration.
  30. Facebook allows developers to create test accounts for testing their applications'
  31. Facebook integration (see https://developers.facebook.com/docs/test_users/). This class
  32. simplifies use of these accounts for writing tests. It is not designed for use in
  33. production application code.
  34. This class will make Graph API calls on behalf of your app to manage test accounts and requires
  35. an app id and app secret. You will typically use this class to write unit or integration tests.
  36. Make sure you NEVER include your app secret in your production app.
  37. */
  38. @interface FBSDKTestUsersManager : NSObject
  39. - (instancetype)init NS_UNAVAILABLE;
  40. + (instancetype)new NS_UNAVAILABLE;
  41. /**
  42. construct or return the shared instance
  43. @param appID the Facebook app id
  44. @param appSecret the Facebook app secret
  45. */
  46. + (instancetype)sharedInstanceForAppID:(NSString *)appID appSecret:(NSString *)appSecret;
  47. /**
  48. retrieve FBSDKAccessToken instances for test accounts with the specific permissions.
  49. @param arraysOfPermissions an array of permissions sets, such as @[ [NSSet setWithObject:@"email"], [NSSet setWithObject:@"user_birthday"]]
  50. if you needed two test accounts with email and birthday permissions, respectively. You can pass in empty nested sets
  51. if you need two arbitrary test accounts. For convenience, passing nil is treated as @[ [NSSet set] ]
  52. for fetching a single test user.
  53. @param createIfNotFound if YES, new test accounts are created if no test accounts existed that fit the permissions
  54. requirement
  55. @param handler the callback to invoke which will return an array of `FBAccessTokenData` instances or an `NSError`.
  56. If param `createIfNotFound` is NO, the array may contain `[NSNull null]` instances.
  57. If you are requesting test accounts with differing number of permissions, try to order
  58. `arrayOfPermissionsArrays` so that the most number of permissions come first to minimize creation of new
  59. test accounts.
  60. */
  61. - (void)requestTestAccountTokensWithArraysOfPermissions:(NSArray *)arraysOfPermissions
  62. createIfNotFound:(BOOL)createIfNotFound
  63. completionHandler:(FBSDKTestUsersManagerRetrieveTestAccountTokensHandler)handler;
  64. /**
  65. add a test account with the specified permissions
  66. @param permissions the set of permissions, e.g., [NSSet setWithObjects:@"email", @"user_friends"]
  67. @param handler the callback handler
  68. */
  69. - (void)addTestAccountWithPermissions:(NSSet *)permissions
  70. completionHandler:(FBSDKTestUsersManagerRetrieveTestAccountTokensHandler)handler;
  71. /**
  72. remove a test account for the given user id
  73. @param userId the user id
  74. @param handler the callback handler
  75. */
  76. - (void)removeTestAccount:(NSString *)userId completionHandler:(FBSDKTestUsersManagerRemoveTestAccountHandler)handler;
  77. /**
  78. Make two test users friends with each other.
  79. @param first the token of the first user
  80. @param second the token of the second user
  81. @param callback the callback handler
  82. */
  83. - (void)makeFriendsWithFirst:(FBSDKAccessToken *)first second:(FBSDKAccessToken *)second callback:(void (^)(NSError *))callback;
  84. @end