Skip to content

Commit 17794e7

Browse files
committed
Merge remote-tracking branch 'support/2.7'
2 parents 58c58d7 + d5bc3a1 commit 17794e7

6 files changed

Lines changed: 389 additions & 141 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
RELEASE_MESSAGE*
22
test*
33
*.jpg
4+
*.mp4

CHANGELOG

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
codebird-php - changelog
22
========================
33

4+
2.7.0 (2015-05-14)
5+
- #92, #108 Fix issues with uploading special chars
6+
+ #109 Proxy support
7+
- Drop support for internal and old API methods
8+
+ #111 Set user agent for remote calls
9+
+ #106 Add logout method
10+
+ #86 Return exception for failed cURL requests
11+
412
2.6.1 (2014-12-13)
513
- #90 Allow uploading media with special chars
614

README.md

Lines changed: 107 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ codebird-php
22
============
33
*A Twitter library in PHP.*
44

5-
Copyright (C) 2010-2014 Jublo Solutions <[email protected]>
5+
Copyright (C) 2010-2015 Jublo Solutions <[email protected]>
66

77
This program is free software: you can redistribute it and/or modify
88
it under the terms of the GNU General Public License as published by
@@ -86,6 +86,15 @@ if (! isset($_SESSION['oauth_token'])) {
8686
$cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
8787
```
8888

89+
### Logging out
90+
91+
In case you want to log out the current user (to log in a different user without
92+
creating a new Codebird object), just call the `logout()` method.
93+
94+
```
95+
$cb->logout();
96+
```
97+
8998
### Application-only auth
9099

91100
Some API methods also support authenticating on a per-application level.
@@ -168,8 +177,9 @@ sent with the code above.
168177

169178
### Uploading media to Twitter
170179

171-
Tweet media can be uploaded in a 2-step process.
172-
**First** you send each image to Twitter, like this:
180+
Tweet media can be uploaded in a 2-step process:
181+
182+
**First** you send each media to Twitter. For **images**, it works like this:
173183

174184
```php
175185
// these files to upload. You can also just upload 1 image!
@@ -189,6 +199,8 @@ foreach ($media_files as $file) {
189199
}
190200
```
191201

202+
Uploading **videos** requires you to send the data in chunks. See the next section on this.
203+
192204
**Second,** you attach the collected media ids for all images to your call
193205
to ```statuses/update```, like this:
194206

@@ -208,7 +220,7 @@ print_r($reply);
208220
Here is a [sample tweet](https://twitter.com/LarryMcTweet/status/475276535386365952)
209221
sent with the code above.
210222

211-
More [documentation for tweeting with media](https://dev.twitter.com/rest/public/uploading-media-multiple-photos) is available on the Twitter Developer site.
223+
More [documentation for uploading media](https://dev.twitter.com/rest/public/uploading-media) is available on the Twitter Developer site.
212224

213225
#### Remote files
214226

@@ -219,6 +231,79 @@ $reply = $cb->media_upload(array(
219231
));
220232
```
221233

234+
:warning: *URLs containing Unicode characters should be normalised. A sample normalisation function can be found at http://stackoverflow.com/a/6059053/1816603*
235+
236+
#### Video files
237+
238+
Uploading videos to Twitter (≤ 15MB, MP4) requires you to send them in chunks.
239+
You need to perform at least 3 calls to obtain your `media_id` for the video:
240+
241+
1. Send an `INIT` event to get a `media_id` draft.
242+
2. Upload your chunks with `APPEND` events, each one up to 5MB in size.
243+
3. Send a `FINALIZE` event to convert the draft to a ready-to-tweet `media_id`.
244+
4. Post your tweet with video attached.
245+
246+
Here’s a sample for video uploads:
247+
248+
```php
249+
$file = 'demo-video.mp4';
250+
$size_bytes = filesize($file);
251+
$fp = fopen($file, 'r');
252+
253+
// INIT the upload
254+
255+
$reply = $cb->media_upload(array(
256+
'command' => 'INIT',
257+
'media_type' => 'video/mp4',
258+
'total_bytes' => $size_bytes
259+
));
260+
261+
$media_id = $reply->media_id_string;
262+
263+
// APPEND data to the upload
264+
265+
$segment_id = 0;
266+
267+
while (! feof($fp)) {
268+
$chunk = fread($fp, 1048576); // 1MB per chunk for this sample
269+
270+
$reply = $cb->media_upload(array(
271+
'command' => 'APPEND',
272+
'media_id' => $media_id,
273+
'segment_index' => $segment_id,
274+
'media' => $chunk
275+
));
276+
277+
$segment_id++;
278+
}
279+
280+
fclose($fp);
281+
282+
// FINALIZE the upload
283+
284+
$reply = $cb->media_upload(array(
285+
'command' => 'FINALIZE',
286+
'media_id' => $media_id
287+
));
288+
289+
var_dump($reply);
290+
291+
if ($reply->httpstatus < 200 || $reply->httpstatus > 299) {
292+
die();
293+
}
294+
295+
// Now use the media_id in a tweet
296+
$reply = $cb->statuses_update(array(
297+
'status' => 'Twitter now accepts video uploads.',
298+
'media_ids' => $media_id
299+
));
300+
```
301+
302+
:warning: The Twitter API reproducibly rejected some MP4 videos even though they are valid. It’s currently undocumented which video codecs are supported and which are not.
303+
304+
:warning: When uploading a video in multiple chunks, you may run into an error `The validation of media ids failed.` even though the `media_id` is correct. This is known. Please check back with this [Twitter community forums thread](https://twittercommunity.com/t/video-uploads-via-rest-api/38177/5).
305+
306+
222307
### Requests with app-only auth
223308

224309
To send API requests without an access token for a user (app-only auth),
@@ -250,7 +335,7 @@ map to Codebird function calls. The general rules are:
250335
Examples:
251336
- ```statuses/show/:id``` maps to ```Codebird::statuses_show_ID('id=12345')```.
252337
- ```users/profile_image/:screen_name``` maps to
253-
```Codebird::users_profileImage_SCREEN_NAME('screen_name=jublonet')```.
338+
`Codebird::users_profileImage_SCREEN_NAME('screen_name=jublonet')`.
254339

255340
HTTP methods (GET, POST, DELETE etc.)
256341
-------------------------------------
@@ -487,3 +572,20 @@ You may also manually disable cURL. Use the following call:
487572
```php
488573
$cb->setUseCurl(false);
489574
```
575+
576+
### …use a proxy?
577+
578+
Codebird allows proxy support for both cURL handles and sockets.
579+
580+
To activate proxy mode, use the following call:
581+
582+
```php
583+
$cb->setProxy('<host>', '<port>');
584+
```
585+
586+
You may also use an authenticated proxy. Use the following call:
587+
588+
```php
589+
$cb->setProxy('<host>', '<port>');
590+
$cb->setProxyAuthentication('<username>:<password>');
591+
```

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codebird-php",
3-
"version": "2.6.1",
3+
"version": "2.7.0",
44
"homepage": "http://www.jublo.net/projects/codebird/php",
55
"authors": [
66
"Joshua Atkins <[email protected]>",

phpunit.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="true"
3+
backupStaticAttributes="false"
4+
strict="true"
5+
colors="true"
6+
verbose="true">
7+
8+
<php>
9+
<const name="TESTSUITE_CONSUMER_KEY" value="PNVfyHvoowa9h0Tt4fF3VQ"/>
10+
<const name="TESTSUITE_CONSUMER_SECRET" value="rny1vPxJ02H8VSaJCxv3QVVU44Kb41Sy3w7EJHmg"/>
11+
<const name="TESTSUITE_ACCESS_TOKEN" value="14648265-rPn8EJwfBG1FAzGmYUd1YxJB18LJwdEpzlNvEM8SZ"/>
12+
<const name="TESTSUITE_ACCESS_TOKEN_SECRET" value="agvf3L3ebF1vXx8VOmofBZvrJBB1KKIPWfLl5TQLk"/>
13+
<const name="TESTSUITE_CODEBIRD_HOST" value="http://localhost" />
14+
<const name="TESTSUITE_CODEBIRD_URL" value="/codebird-php" />
15+
</php>
16+
17+
<testsuites>
18+
<testsuite name="Environment">
19+
<file>test/environment_test.php</file>
20+
</testsuite>
21+
<testsuite name="Unit">
22+
<directory suffix="_tests.php">test</directory>
23+
</testsuite>
24+
</testsuites>
25+
<!--
26+
<logging>
27+
<log type="coverage-html" target="build/coverage" title="codebird-php"
28+
charset="UTF-8" yui="true" highlight="true"
29+
lowUpperBound="35" highLowerBound="70"/>
30+
<log type="coverage-clover" target="build/logs/clover.xml"/>
31+
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
32+
</logging>
33+
-->
34+
<filter>
35+
<whitelist addUncoveredFilesFromWhitelist="true">
36+
<directory suffix=".php">.</directory>
37+
</whitelist>
38+
</filter>
39+
</phpunit>

0 commit comments

Comments
 (0)