@@ -2,7 +2,7 @@ codebird-php
2
2
============
3
3
* A Twitter library in PHP.*
4
4
5
- Copyright (C) 2010-2014 Jublo Solutions & lt ; support@jublo.net & gt ;
5
+ Copyright (C) 2010-2014 Jublo Solutions < support@jublo.net >
6
6
7
7
This program is free software: you can redistribute it and/or modify
8
8
it under the terms of the GNU General Public License as published by
@@ -17,20 +17,15 @@ GNU General Public License for more details.
17
17
You should have received a copy of the GNU General Public License
18
18
along with this program. If not, see < http://www.gnu.org/licenses/ > .
19
19
20
- ### Versions
21
-
22
- - JavaScript: https://github.com/jublonet/codebird-js
23
- - PHP: https://github.com/jublonet/codebird-php
24
-
25
20
### Requirements
26
21
27
22
- PHP 5.3.0 or higher
28
23
- CURL extension
29
24
- OpenSSL extension
30
25
31
26
32
- 1 . Authentication
33
- -----------------
27
+ Authentication
28
+ --------------
34
29
35
30
To authenticate your API requests on behalf of a certain Twitter user
36
31
(following OAuth 1.0a), take a look at these steps:
@@ -92,7 +87,7 @@ if (! isset($_SESSION['oauth_token'])) {
92
87
$cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
93
88
```
94
89
95
- ### 1.1. Application-only auth
90
+ ### Application-only auth
96
91
97
92
Some API methods also support authenticating on a per-application level.
98
93
This is useful for getting data that are not directly related to a specific
@@ -117,8 +112,8 @@ If you already have your token, tell Codebird to use it:
117
112
For sending an API request with app-only auth, see the ‘Usage examples’ section.
118
113
119
114
120
- 2 . Usage examples
121
- -----------------
115
+ Usage examples
116
+ --------------
122
117
123
118
When you have an access token, calling the API is simple:
124
119
@@ -206,8 +201,8 @@ $reply = $cb->search_tweets('q=Twitter', true);
206
201
207
202
Bear in mind that not all API methods support application-only auth.
208
203
209
- 3 . Mapping API methods to Codebird function calls
210
- -------------------------------------------------
204
+ Mapping API methods to Codebird function calls
205
+ ----------------------------------------------
211
206
212
207
As you can see from the last example, there is a general way how Twitter’s API methods
213
208
map to Codebird function calls. The general rules are:
@@ -228,19 +223,19 @@ map to Codebird function calls. The general rules are:
228
223
- ``` users/profile_image/:screen_name ``` maps to
229
224
``` Codebird::users_profileImage_SCREEN_NAME('screen_name=jublonet') ``` .
230
225
231
- 4 . HTTP methods (GET, POST, DELETE etc.)
232
- ----------------------------------------
226
+ HTTP methods (GET, POST, DELETE etc.)
227
+ -------------------------------------
233
228
234
229
Never care about which HTTP method (verb) to use when calling a Twitter API.
235
230
Codebird is intelligent enough to find out on its own.
236
231
237
- 5 . Response codes
238
- -----------------
232
+ Response codes
233
+ --------------
239
234
240
235
The HTTP response code that the API gave is included in any return values.
241
236
You can find it within the return object’s ``` httpstatus ``` property.
242
237
243
- ### 5.1 Dealing with rate-limits
238
+ ### Dealing with rate-limits
244
239
245
240
Basically, Codebird leaves it up to you to handle Twitter’s rate limit.
246
241
The library returns the response HTTP status code, so you can detect rate limits.
@@ -252,10 +247,11 @@ See the [Rate Limiting FAQ](https://dev.twitter.com/docs/rate-limiting-faq)
252
247
for more information.
253
248
254
249
Unless your return format is JOSN, you will receive rate-limiting details
255
- in the returned data’s ``` $reply->rate ``` property.
250
+ in the returned data’s ``` $reply->rate ``` property,
251
+ if the Twitter API responds with rate-limiting HTTP headers.
256
252
257
- 6 . Return formats
258
- -----------------
253
+ Return formats
254
+ --------------
259
255
The default return format for API calls is a PHP object.
260
256
For API methods returning multiple data (like ``` statuses/home_timeline ``` ),
261
257
you should cast the reply to array, like this:
@@ -278,10 +274,8 @@ To get a JSON string, set the corresponding return format:
278
274
$cb->setReturnFormat(CODEBIRD_RETURNFORMAT_JSON);
279
275
```
280
276
281
- Support for getting a SimpleXML object is planned.
282
-
283
- 7 . Using multiple Codebird instances
284
- ------------------------------------
277
+ Using multiple Codebird instances
278
+ ---------------------------------
285
279
286
280
By default, Codebird works with just one instance. This programming paradigma is
287
281
called a * singleton* .
@@ -306,10 +300,9 @@ multiple Codebird instances, while the OAuth request and access tokens with thei
306
300
secrets are * not* shared.
307
301
308
302
How Do I…?
309
- ==========
303
+ ----------
310
304
311
- …access a user’s profile image?
312
- -------------------------------
305
+ ### …access a user’s profile image?
313
306
314
307
First retrieve the user object using
315
308
@@ -325,8 +318,7 @@ For example:
325
318
326
319
``` $reply['profile_image_url'] ``` will then return the profile image url without https.
327
320
328
- …get user ID, screen name and more details about the current user?
329
- ------------------------------------------------------------------
321
+ ### …get user ID, screen name and more details about the current user?
330
322
331
323
When the user returns from the authentication screen, you need to trade
332
324
the obtained request token for an access token, using the OAuth verifier.
@@ -362,8 +354,7 @@ print_r($reply);
362
354
I suggest to cache the User Entity after obtaining it, as the
363
355
``` account/verify_credentials ``` method is rate-limited by 15 calls per 15 minutes.
364
356
365
- …walk through cursored results?
366
- -------------------------------
357
+ ### …walk through cursored results?
367
358
368
359
The Twitter REST API utilizes a technique called ‘cursoring’ to paginate
369
360
large result sets. Cursoring separates results into pages of no more than
@@ -396,8 +387,7 @@ It might make sense to use the cursors in a loop. Watch out, though,
396
387
not to send more than the allowed number of requests to ``` followers/list ```
397
388
per rate-limit timeframe, or else you will hit your rate-limit.
398
389
399
- …use xAuth with Codebird?
400
- -------------------------
390
+ ### …use xAuth with Codebird?
401
391
402
392
Codebird supports xAuth just like every other authentication used at Twitter.
403
393
Remember that your application needs to be whitelisted to be able to use xAuth.
@@ -432,8 +422,7 @@ When this error occurs, advise the user to
432
422
[ generate a temporary password] ( https://twitter.com/settings/applications )
433
423
on twitter.com and use that to complete signing in to the application.
434
424
435
- …know what cacert.pem is for?
436
- -----------------------------
425
+ ### …know what cacert.pem is for?
437
426
438
427
Connections to the Twitter API are done over a secured SSL connection.
439
428
Since 2.4.0, codebird-php checks if the Twitter API server has a valid
@@ -442,8 +431,7 @@ The cacert.pem file contains a list of all public certificates for root
442
431
certificate authorities. You can find more information about this file
443
432
at http://curl.haxx.se/docs/caextract.html .
444
433
445
- …set the timeout for requests to the Twitter API?
446
- -------------------------------------------------
434
+ ### …set the timeout for requests to the Twitter API?
447
435
448
436
For connecting to Twitter, Codebird uses the cURL library.
449
437
You can specify both the connection timeout and the request timeout,
0 commit comments