1 | <?php |
||
36 | class FacebookClient |
||
37 | { |
||
38 | /** |
||
39 | * @const string Production Graph API URL. |
||
40 | */ |
||
41 | const BASE_GRAPH_URL = 'https://graph.facebook.com'; |
||
42 | |||
43 | /** |
||
44 | * @const string Graph API URL for video uploads. |
||
45 | */ |
||
46 | const BASE_GRAPH_VIDEO_URL = 'https://graph-video.facebook.com'; |
||
47 | |||
48 | /** |
||
49 | * @const string Beta Graph API URL. |
||
50 | */ |
||
51 | const BASE_GRAPH_URL_BETA = 'https://graph.beta.facebook.com'; |
||
52 | |||
53 | /** |
||
54 | * @const string Beta Graph API URL for video uploads. |
||
55 | */ |
||
56 | const BASE_GRAPH_VIDEO_URL_BETA = 'https://graph-video.beta.facebook.com'; |
||
57 | |||
58 | /** |
||
59 | * @const int The timeout in seconds for a normal request. |
||
60 | */ |
||
61 | const DEFAULT_REQUEST_TIMEOUT = 60; |
||
62 | |||
63 | /** |
||
64 | * @const int The timeout in seconds for a request that contains file uploads. |
||
65 | */ |
||
66 | const DEFAULT_FILE_UPLOAD_REQUEST_TIMEOUT = 3600; |
||
67 | |||
68 | /** |
||
69 | * @const int The timeout in seconds for a request that contains video uploads. |
||
70 | */ |
||
71 | const DEFAULT_VIDEO_UPLOAD_REQUEST_TIMEOUT = 7200; |
||
72 | |||
73 | /** |
||
74 | * @var bool Toggle to use Graph beta url. |
||
75 | */ |
||
76 | protected $enableBetaMode = false; |
||
77 | |||
78 | /** |
||
79 | * @var FacebookHttpClientInterface HTTP client handler. |
||
80 | */ |
||
81 | protected $httpClientHandler; |
||
82 | |||
83 | /** |
||
84 | * @var int The number of calls that have been made to Graph. |
||
85 | */ |
||
86 | public static $requestCount = 0; |
||
87 | |||
88 | /** |
||
89 | * Instantiates a new FacebookClient object. |
||
90 | * |
||
91 | * @param FacebookHttpClientInterface|null $httpClientHandler |
||
92 | * @param boolean $enableBeta |
||
93 | */ |
||
94 | public function __construct(FacebookHttpClientInterface $httpClientHandler = null, $enableBeta = false) |
||
99 | |||
100 | /** |
||
101 | * Sets the HTTP client handler. |
||
102 | * |
||
103 | * @param FacebookHttpClientInterface $httpClientHandler |
||
104 | */ |
||
105 | public function setHttpClientHandler(FacebookHttpClientInterface $httpClientHandler) |
||
109 | |||
110 | /** |
||
111 | * Returns the HTTP client handler. |
||
112 | * |
||
113 | * @return FacebookHttpClientInterface |
||
114 | */ |
||
115 | public function getHttpClientHandler() |
||
119 | |||
120 | /** |
||
121 | * Detects which HTTP client handler to use. |
||
122 | * |
||
123 | * @return FacebookHttpClientInterface |
||
124 | */ |
||
125 | public function detectHttpClientHandler() |
||
129 | |||
130 | /** |
||
131 | * Toggle beta mode. |
||
132 | * |
||
133 | * @param boolean $betaMode |
||
134 | */ |
||
135 | public function enableBetaMode($betaMode = true) |
||
139 | |||
140 | /** |
||
141 | * Returns the base Graph URL. |
||
142 | * |
||
143 | * @param boolean $postToVideoUrl Post to the video API if videos are being uploaded. |
||
144 | * |
||
145 | * @return string |
||
146 | */ |
||
147 | public function getBaseGraphUrl($postToVideoUrl = false) |
||
155 | |||
156 | /** |
||
157 | * Prepares the request for sending to the client handler. |
||
158 | * |
||
159 | * @param FacebookRequest $request |
||
160 | * |
||
161 | * @return array |
||
162 | */ |
||
163 | public function prepareRequestMessage(FacebookRequest $request) |
||
188 | |||
189 | /** |
||
190 | * Makes the request to Graph and returns the result. |
||
191 | * |
||
192 | * @param FacebookRequest $request |
||
193 | * |
||
194 | * @return FacebookResponse |
||
195 | * |
||
196 | * @throws FacebookSDKException |
||
197 | */ |
||
198 | public function sendRequest(FacebookRequest $request) |
||
233 | |||
234 | /** |
||
235 | * Makes a batched request to Graph and returns the result. |
||
236 | * |
||
237 | * @param FacebookBatchRequest $request |
||
238 | * |
||
239 | * @return FacebookBatchResponse |
||
240 | * |
||
241 | * @throws FacebookSDKException |
||
242 | */ |
||
243 | public function sendBatchRequest(FacebookBatchRequest $request) |
||
250 | } |
||
251 |