FBSDKGraphRequest.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #import <FBSDKCoreKit/FBSDKGraphRequestConnection.h>
  20. @class FBSDKAccessToken;
  21. /**
  22. Represents a request to the Facebook Graph API.
  23. `FBSDKGraphRequest` encapsulates the components of a request (the
  24. Graph API path, the parameters, error recovery behavior) and should be
  25. used in conjunction with `FBSDKGraphRequestConnection` to issue the request.
  26. Nearly all Graph APIs require an access token. Unless specified, the
  27. `[FBSDKAccessToken currentAccessToken]` is used. Therefore, most requests
  28. will require login first (see `FBSDKLoginManager` in FBSDKLoginKit.framework).
  29. A `- start` method is provided for convenience for single requests.
  30. By default, FBSDKGraphRequest will attempt to recover any errors returned from
  31. Facebook. You can disable this via `disableErrorRecovery:`.
  32. @see FBSDKGraphErrorRecoveryProcessor
  33. */
  34. @interface FBSDKGraphRequest : NSObject
  35. - (instancetype)init NS_UNAVAILABLE;
  36. + (instancetype)new NS_UNAVAILABLE;
  37. /**
  38. Initializes a new instance that use use `[FBSDKAccessToken currentAccessToken]`.
  39. @param graphPath the graph path (e.g., @"me").
  40. @param parameters the optional parameters dictionary.
  41. */
  42. - (instancetype)initWithGraphPath:(NSString *)graphPath
  43. parameters:(NSDictionary *)parameters;
  44. /**
  45. Initializes a new instance that use use `[FBSDKAccessToken currentAccessToken]`.
  46. @param graphPath the graph path (e.g., @"me").
  47. @param parameters the optional parameters dictionary.
  48. @param HTTPMethod the optional HTTP method. nil defaults to @"GET".
  49. */
  50. - (instancetype)initWithGraphPath:(NSString *)graphPath
  51. parameters:(NSDictionary *)parameters
  52. HTTPMethod:(NSString *)HTTPMethod;
  53. /**
  54. Initializes a new instance.
  55. @param graphPath the graph path (e.g., @"me").
  56. @param parameters the optional parameters dictionary.
  57. @param tokenString the token string to use. Specifying nil will cause no token to be used.
  58. @param version the optional Graph API version (e.g., @"v2.0"). nil defaults to `[FBSDKSettings graphAPIVersion]`.
  59. @param HTTPMethod the optional HTTP method (e.g., @"POST"). nil defaults to @"GET".
  60. */
  61. - (instancetype)initWithGraphPath:(NSString *)graphPath
  62. parameters:(NSDictionary *)parameters
  63. tokenString:(NSString *)tokenString
  64. version:(NSString *)version
  65. HTTPMethod:(NSString *)HTTPMethod
  66. NS_DESIGNATED_INITIALIZER;
  67. /**
  68. The request parameters.
  69. */
  70. @property (nonatomic, strong, readonly) NSMutableDictionary *parameters;
  71. /**
  72. The access token string used by the request.
  73. */
  74. @property (nonatomic, copy, readonly) NSString *tokenString;
  75. /**
  76. The Graph API endpoint to use for the request, for example "me".
  77. */
  78. @property (nonatomic, copy, readonly) NSString *graphPath;
  79. /**
  80. The HTTPMethod to use for the request, for example "GET" or "POST".
  81. */
  82. @property (nonatomic, copy, readonly) NSString *HTTPMethod;
  83. /**
  84. The Graph API version to use (e.g., "v2.0")
  85. */
  86. @property (nonatomic, copy, readonly) NSString *version;
  87. /**
  88. If set, disables the automatic error recovery mechanism.
  89. @param disable whether to disable the automatic error recovery mechanism
  90. By default, non-batched FBSDKGraphRequest instances will automatically try to recover
  91. from errors by constructing a `FBSDKGraphErrorRecoveryProcessor` instance that
  92. re-issues the request on successful recoveries. The re-issued request will call the same
  93. handler as the receiver but may occur with a different `FBSDKGraphRequestConnection` instance.
  94. This will override [FBSDKSettings setGraphErrorRecoveryDisabled:].
  95. */
  96. - (void)setGraphErrorRecoveryDisabled:(BOOL)disable;
  97. /**
  98. Starts a connection to the Graph API.
  99. @param handler The handler block to call when the request completes.
  100. */
  101. - (FBSDKGraphRequestConnection *)startWithCompletionHandler:(FBSDKGraphRequestHandler)handler;
  102. @end