FBSDKGraphRequest.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * Copyright (c) Meta Platforms, Inc. and affiliates.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. */
  8. #import <Foundation/Foundation.h>
  9. #import <FBSDKCoreKit/FBSDKGraphRequestConnecting.h>
  10. #import <FBSDKCoreKit/FBSDKGraphRequestConnectionFactoryProtocol.h>
  11. #import <FBSDKCoreKit/FBSDKGraphRequestHTTPMethod.h>
  12. #import <FBSDKCoreKit/FBSDKGraphRequestProtocol.h>
  13. #import <FBSDKCoreKit/FBSDKTokenStringProviding.h>
  14. @protocol FBSDKSettings;
  15. NS_ASSUME_NONNULL_BEGIN
  16. /**
  17. Represents a request to the Facebook Graph API.
  18. `FBSDKGraphRequest` encapsulates the components of a request (the
  19. Graph API path, the parameters, error recovery behavior) and should be
  20. used in conjunction with `FBSDKGraphRequestConnection` to issue the request.
  21. Nearly all Graph APIs require an access token. Unless specified, the
  22. `[FBSDKAccessToken currentAccessToken]` is used. Therefore, most requests
  23. will require login first (see `FBSDKLoginManager` in FBSDKLoginKit.framework).
  24. A `- start` method is provided for convenience for single requests.
  25. By default, FBSDKGraphRequest will attempt to recover any errors returned from
  26. Facebook. You can disable this via `disableErrorRecovery:`.
  27. See FBSDKGraphErrorRecoveryProcessor
  28. */
  29. NS_SWIFT_NAME(GraphRequest)
  30. @interface FBSDKGraphRequest : NSObject <FBSDKGraphRequest>
  31. - (instancetype)init NS_UNAVAILABLE;
  32. + (instancetype)new NS_UNAVAILABLE;
  33. /**
  34. Internal method exposed to facilitate transition to Swift.
  35. API Subject to change or removal without warning. Do not use.
  36. @warning INTERNAL - DO NOT USE
  37. */
  38. // UNCRUSTIFY_FORMAT_OFF
  39. + (void) configureWithSettings:(id<FBSDKSettings>)settings
  40. currentAccessTokenStringProvider:(Class<FBSDKTokenStringProviding>)accessTokenProvider
  41. graphRequestConnectionFactory:(id<FBSDKGraphRequestConnectionFactory>)_graphRequestConnectionFactory
  42. NS_SWIFT_NAME(configure(settings:currentAccessTokenStringProvider:graphRequestConnectionFactory:));
  43. // UNCRUSTIFY_FORMAT_ON
  44. /**
  45. Initializes a new instance that use use `[FBSDKAccessToken currentAccessToken]`.
  46. @param graphPath the graph path (e.g., @"me").
  47. */
  48. - (instancetype)initWithGraphPath:(NSString *)graphPath;
  49. /**
  50. Initializes a new instance that use use `[FBSDKAccessToken currentAccessToken]`.
  51. @param graphPath the graph path (e.g., @"me").
  52. */
  53. - (instancetype)initWithGraphPath:(NSString *)graphPath
  54. useAlternativeDefaultDomainPrefix:(BOOL)useAlternativeDefaultDomainPrefix;
  55. /**
  56. Initializes a new instance that use use `[FBSDKAccessToken currentAccessToken]`.
  57. @param graphPath the graph path (e.g., @"me").
  58. @param method the HTTP method. Empty String defaults to @"GET".
  59. */
  60. - (instancetype)initWithGraphPath:(NSString *)graphPath
  61. HTTPMethod:(FBSDKHTTPMethod)method;
  62. /**
  63. Initializes a new instance that use use `[FBSDKAccessToken currentAccessToken]`.
  64. @param graphPath the graph path (e.g., @"me").
  65. @param parameters the optional parameters dictionary.
  66. */
  67. - (instancetype)initWithGraphPath:(NSString *)graphPath
  68. parameters:(NSDictionary<NSString *, id> *)parameters;
  69. /**
  70. Initializes a new instance that use use `[FBSDKAccessToken currentAccessToken]`.
  71. @param graphPath the graph path (e.g., @"me").
  72. @param parameters the optional parameters dictionary.
  73. */
  74. - (instancetype)initWithGraphPath:(NSString *)graphPath
  75. parameters:(NSDictionary<NSString *, id> *)parameters
  76. useAlternativeDefaultDomainPrefix:(BOOL)useAlternativeDefaultDomainPrefix;
  77. /**
  78. Initializes a new instance that use use `[FBSDKAccessToken currentAccessToken]`.
  79. @param graphPath the graph path (e.g., @"me").
  80. @param parameters the optional parameters dictionary.
  81. @param method the HTTP method. Empty String defaults to @"GET".
  82. */
  83. - (instancetype)initWithGraphPath:(NSString *)graphPath
  84. parameters:(NSDictionary<NSString *, id> *)parameters
  85. HTTPMethod:(FBSDKHTTPMethod)method;
  86. /**
  87. Initializes a new instance that use use `[FBSDKAccessToken currentAccessToken]`.
  88. @param graphPath the graph path (e.g., @"me").
  89. @param parameters the optional parameters dictionary.
  90. @param method the HTTP method. Empty String defaults to @"GET".
  91. */
  92. - (instancetype)initWithGraphPath:(NSString *)graphPath
  93. parameters:(NSDictionary<NSString *, id> *)parameters
  94. HTTPMethod:(FBSDKHTTPMethod)method
  95. useAlternativeDefaultDomainPrefix:(BOOL)useAlternativeDefaultDomainPrefix;
  96. /**
  97. Initializes a new instance.
  98. @param graphPath the graph path (e.g., @"me").
  99. @param parameters the optional parameters dictionary.
  100. @param tokenString the token string to use. Specifying nil will cause no token to be used.
  101. @param version the optional Graph API version (e.g., @"v2.0"). nil defaults to `[FBSDKSettings graphAPIVersion]`.
  102. @param method the HTTP method. Empty String defaults to @"GET".
  103. */
  104. - (instancetype)initWithGraphPath:(NSString *)graphPath
  105. parameters:(NSDictionary<NSString *, id> *)parameters
  106. tokenString:(nullable NSString *)tokenString
  107. version:(nullable NSString *)version
  108. HTTPMethod:(FBSDKHTTPMethod)method;
  109. /**
  110. Initializes a new instance.
  111. @param graphPath the graph path (e.g., @"me").
  112. @param parameters the optional parameters dictionary.
  113. @param tokenString the token string to use. Specifying nil will cause no token to be used.
  114. @param version the optional Graph API version (e.g., @"v2.0"). nil defaults to `[FBSDKSettings graphAPIVersion]`.
  115. @param method the HTTP method. Empty String defaults to @"GET".
  116. @param forAppEvents a convenience flag indicating if the request is for sending app events.
  117. */
  118. - (instancetype)initWithGraphPath:(NSString *)graphPath
  119. parameters:(NSDictionary<NSString *, id> *)parameters
  120. tokenString:(nullable NSString *)tokenString
  121. version:(nullable NSString *)version
  122. HTTPMethod:(FBSDKHTTPMethod)method
  123. forAppEvents:(BOOL)forAppEvents;
  124. /**
  125. Initializes a new instance.
  126. @param graphPath the graph path (e.g., @"me").
  127. @param parameters the optional parameters dictionary.
  128. @param tokenString the token string to use. Specifying nil will cause no token to be used.
  129. @param version the optional Graph API version (e.g., @"v2.0"). nil defaults to `[FBSDKSettings graphAPIVersion]`.
  130. @param method the HTTP method. Empty String defaults to @"GET".
  131. @param forAppEvents a convenience flag indicating if the request is for sending app events.
  132. */
  133. - (instancetype)initWithGraphPath:(NSString *)graphPath
  134. parameters:(NSDictionary<NSString *, id> *)parameters
  135. tokenString:(nullable NSString *)tokenString
  136. version:(nullable NSString *)version
  137. HTTPMethod:(FBSDKHTTPMethod)method
  138. forAppEvents:(BOOL)forAppEvents
  139. useAlternativeDefaultDomainPrefix:(BOOL)useAlternativeDefaultDomainPrefix
  140. NS_DESIGNATED_INITIALIZER;
  141. /**
  142. Initializes a new instance.
  143. @param graphPath the graph path (e.g., @"me").
  144. @param parameters the optional parameters dictionary.
  145. @param requestFlags flags that indicate how a graph request should be treated in various scenarios
  146. */
  147. - (instancetype)initWithGraphPath:(NSString *)graphPath
  148. parameters:(nullable NSDictionary<NSString *, id> *)parameters
  149. flags:(FBSDKGraphRequestFlags)requestFlags;
  150. /**
  151. Initializes a new instance.
  152. @param graphPath the graph path (e.g., @"me").
  153. @param parameters the optional parameters dictionary.
  154. @param requestFlags flags that indicate how a graph request should be treated in various scenarios
  155. */
  156. - (instancetype)initWithGraphPath:(NSString *)graphPath
  157. parameters:(nullable NSDictionary<NSString *, id> *)parameters
  158. flags:(FBSDKGraphRequestFlags)requestFlags
  159. useAlternativeDefaultDomainPrefix:(BOOL)useAlternativeDefaultDomainPrefix;
  160. /**
  161. Initializes a new instance.
  162. @param graphPath the graph path (e.g., @"me").
  163. @param parameters the optional parameters dictionary.
  164. @param tokenString the token string to use. Specifying nil will cause no token to be used.
  165. @param HTTPMethod the HTTP method. Empty String defaults to @"GET".
  166. @param flags flags that indicate how a graph request should be treated in various scenarios
  167. */
  168. - (instancetype)initWithGraphPath:(NSString *)graphPath
  169. parameters:(nullable NSDictionary<NSString *, id> *)parameters
  170. tokenString:(nullable NSString *)tokenString
  171. HTTPMethod:(nullable NSString *)HTTPMethod
  172. flags:(FBSDKGraphRequestFlags)flags;
  173. /**
  174. Initializes a new instance.
  175. @param graphPath the graph path (e.g., @"me").
  176. @param parameters the optional parameters dictionary.
  177. @param tokenString the token string to use. Specifying nil will cause no token to be used.
  178. @param HTTPMethod the HTTP method. Empty String defaults to @"GET".
  179. @param flags flags that indicate how a graph request should be treated in various scenarios
  180. */
  181. - (instancetype)initWithGraphPath:(NSString *)graphPath
  182. parameters:(nullable NSDictionary<NSString *, id> *)parameters
  183. tokenString:(nullable NSString *)tokenString
  184. HTTPMethod:(nullable NSString *)HTTPMethod
  185. flags:(FBSDKGraphRequestFlags)flags
  186. useAlternativeDefaultDomainPrefix:(BOOL)useAlternativeDefaultDomainPrefix;;
  187. /**
  188. Initializes a new instance.
  189. @param graphPath the graph path (e.g., @"me").
  190. @param parameters the optional parameters dictionary.
  191. @param tokenString the token string to use. Specifying nil will cause no token to be used.
  192. @param method the HTTP method. Empty String defaults to @"GET".
  193. @param requestFlags flags that indicate how a graph request should be treated in various scenarios
  194. @param forAppEvents a convenience flag indicating if the request is for sending app events.
  195. */
  196. - (instancetype)initWithGraphPath:(NSString *)graphPath
  197. parameters:(nullable NSDictionary<NSString *, id> *)parameters
  198. tokenString:(nullable NSString *)tokenString
  199. HTTPMethod:(nullable NSString *)method
  200. flags:(FBSDKGraphRequestFlags)requestFlags
  201. forAppEvents:(BOOL)forAppEvents;
  202. /**
  203. Initializes a new instance.
  204. @param graphPath the graph path (e.g., @"me").
  205. @param parameters the optional parameters dictionary.
  206. @param tokenString the token string to use. Specifying nil will cause no token to be used.
  207. @param method the HTTP method. Empty String defaults to @"GET".
  208. @param requestFlags flags that indicate how a graph request should be treated in various scenarios
  209. @param forAppEvents a convenience flag indicating if the request is for sending app events.
  210. */
  211. - (instancetype)initWithGraphPath:(NSString *)graphPath
  212. parameters:(nullable NSDictionary<NSString *, id> *)parameters
  213. tokenString:(nullable NSString *)tokenString
  214. HTTPMethod:(nullable NSString *)method
  215. flags:(FBSDKGraphRequestFlags)requestFlags
  216. forAppEvents:(BOOL)forAppEvents
  217. useAlternativeDefaultDomainPrefix:(BOOL)useAlternativeDefaultDomainPrefix;
  218. /// The request parameters.
  219. @property (nonatomic, copy) NSDictionary<NSString *, id> *parameters;
  220. /// The access token string used by the request.
  221. @property (nullable, nonatomic, readonly, copy) NSString *tokenString;
  222. /// The Graph API endpoint to use for the request, for example "me".
  223. @property (nonatomic, readonly, copy) NSString *graphPath;
  224. /// The HTTPMethod to use for the request, for example "GET" or "POST".
  225. @property (nonatomic, readonly, copy) FBSDKHTTPMethod HTTPMethod;
  226. /// The Graph API version to use (e.g., "v2.0")
  227. @property (nonatomic, readonly, copy) NSString *version;
  228. @property (nonatomic, readonly, assign) BOOL forAppEvents;
  229. @property (nonatomic, readonly, assign) BOOL useAlternativeDefaultDomainPrefix;
  230. /**
  231. If set, disables the automatic error recovery mechanism.
  232. @param disable whether to disable the automatic error recovery mechanism
  233. By default, non-batched FBSDKGraphRequest instances will automatically try to recover
  234. from errors by constructing a `FBSDKGraphErrorRecoveryProcessor` instance that
  235. re-issues the request on successful recoveries. The re-issued request will call the same
  236. handler as the receiver but may occur with a different `FBSDKGraphRequestConnection` instance.
  237. This will override [FBSDKSettings setGraphErrorRecoveryDisabled:].
  238. */
  239. // UNCRUSTIFY_FORMAT_OFF
  240. - (void)setGraphErrorRecoveryDisabled:(BOOL)disable
  241. NS_SWIFT_NAME(setGraphErrorRecovery(disabled:));
  242. // UNCRUSTIFY_FORMAT_ON
  243. /**
  244. Starts a connection to the Graph API.
  245. @param completion The handler block to call when the request completes.
  246. */
  247. - (id<FBSDKGraphRequestConnecting>)startWithCompletion:(nullable FBSDKGraphRequestCompletion)completion;
  248. @end
  249. NS_ASSUME_NONNULL_END