-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'support/2.7'
- Loading branch information
Showing
6 changed files
with
389 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
RELEASE_MESSAGE* | ||
test* | ||
*.jpg | ||
*.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ codebird-php | |
============ | ||
*A Twitter library in PHP.* | ||
|
||
Copyright (C) 2010-2014 Jublo Solutions <[email protected]> | ||
Copyright (C) 2010-2015 Jublo Solutions <[email protected]> | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
|
@@ -86,6 +86,15 @@ if (! isset($_SESSION['oauth_token'])) { | |
$cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); | ||
``` | ||
|
||
### Logging out | ||
|
||
In case you want to log out the current user (to log in a different user without | ||
creating a new Codebird object), just call the `logout()` method. | ||
|
||
``` | ||
$cb->logout(); | ||
``` | ||
|
||
### Application-only auth | ||
|
||
Some API methods also support authenticating on a per-application level. | ||
|
@@ -168,8 +177,9 @@ sent with the code above. | |
|
||
### Uploading media to Twitter | ||
|
||
Tweet media can be uploaded in a 2-step process. | ||
**First** you send each image to Twitter, like this: | ||
Tweet media can be uploaded in a 2-step process: | ||
|
||
**First** you send each media to Twitter. For **images**, it works like this: | ||
|
||
```php | ||
// these files to upload. You can also just upload 1 image! | ||
|
@@ -189,6 +199,8 @@ foreach ($media_files as $file) { | |
} | ||
``` | ||
|
||
Uploading **videos** requires you to send the data in chunks. See the next section on this. | ||
|
||
**Second,** you attach the collected media ids for all images to your call | ||
to ```statuses/update```, like this: | ||
|
||
|
@@ -208,7 +220,7 @@ print_r($reply); | |
Here is a [sample tweet](https://twitter.com/LarryMcTweet/status/475276535386365952) | ||
sent with the code above. | ||
|
||
More [documentation for tweeting with media](https://dev.twitter.com/rest/public/uploading-media-multiple-photos) is available on the Twitter Developer site. | ||
More [documentation for uploading media](https://dev.twitter.com/rest/public/uploading-media) is available on the Twitter Developer site. | ||
|
||
#### Remote files | ||
|
||
|
@@ -219,6 +231,79 @@ $reply = $cb->media_upload(array( | |
)); | ||
``` | ||
|
||
:warning: *URLs containing Unicode characters should be normalised. A sample normalisation function can be found at http://stackoverflow.com/a/6059053/1816603* | ||
|
||
#### Video files | ||
|
||
Uploading videos to Twitter (≤ 15MB, MP4) requires you to send them in chunks. | ||
You need to perform at least 3 calls to obtain your `media_id` for the video: | ||
|
||
1. Send an `INIT` event to get a `media_id` draft. | ||
2. Upload your chunks with `APPEND` events, each one up to 5MB in size. | ||
3. Send a `FINALIZE` event to convert the draft to a ready-to-tweet `media_id`. | ||
4. Post your tweet with video attached. | ||
|
||
Here’s a sample for video uploads: | ||
|
||
```php | ||
$file = 'demo-video.mp4'; | ||
$size_bytes = filesize($file); | ||
$fp = fopen($file, 'r'); | ||
|
||
// INIT the upload | ||
|
||
$reply = $cb->media_upload(array( | ||
'command' => 'INIT', | ||
'media_type' => 'video/mp4', | ||
'total_bytes' => $size_bytes | ||
)); | ||
|
||
$media_id = $reply->media_id_string; | ||
|
||
// APPEND data to the upload | ||
|
||
$segment_id = 0; | ||
|
||
while (! feof($fp)) { | ||
$chunk = fread($fp, 1048576); // 1MB per chunk for this sample | ||
|
||
$reply = $cb->media_upload(array( | ||
'command' => 'APPEND', | ||
'media_id' => $media_id, | ||
'segment_index' => $segment_id, | ||
'media' => $chunk | ||
)); | ||
|
||
$segment_id++; | ||
} | ||
|
||
fclose($fp); | ||
|
||
// FINALIZE the upload | ||
|
||
$reply = $cb->media_upload(array( | ||
'command' => 'FINALIZE', | ||
'media_id' => $media_id | ||
)); | ||
|
||
var_dump($reply); | ||
|
||
if ($reply->httpstatus < 200 || $reply->httpstatus > 299) { | ||
die(); | ||
} | ||
|
||
// Now use the media_id in a tweet | ||
$reply = $cb->statuses_update(array( | ||
'status' => 'Twitter now accepts video uploads.', | ||
'media_ids' => $media_id | ||
)); | ||
``` | ||
|
||
: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. | ||
|
||
: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). | ||
|
||
|
||
### Requests with app-only auth | ||
|
||
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: | |
Examples: | ||
- ```statuses/show/:id``` maps to ```Codebird::statuses_show_ID('id=12345')```. | ||
- ```users/profile_image/:screen_name``` maps to | ||
```Codebird::users_profileImage_SCREEN_NAME('screen_name=jublonet')```. | ||
`Codebird::users_profileImage_SCREEN_NAME('screen_name=jublonet')`. | ||
|
||
HTTP methods (GET, POST, DELETE etc.) | ||
------------------------------------- | ||
|
@@ -487,3 +572,20 @@ You may also manually disable cURL. Use the following call: | |
```php | ||
$cb->setUseCurl(false); | ||
``` | ||
|
||
### …use a proxy? | ||
|
||
Codebird allows proxy support for both cURL handles and sockets. | ||
|
||
To activate proxy mode, use the following call: | ||
|
||
```php | ||
$cb->setProxy('<host>', '<port>'); | ||
``` | ||
|
||
You may also use an authenticated proxy. Use the following call: | ||
|
||
```php | ||
$cb->setProxy('<host>', '<port>'); | ||
$cb->setProxyAuthentication('<username>:<password>'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "codebird-php", | ||
"version": "2.6.1", | ||
"version": "2.7.0", | ||
"homepage": "http://www.jublo.net/projects/codebird/php", | ||
"authors": [ | ||
"Joshua Atkins <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="true" | ||
backupStaticAttributes="false" | ||
strict="true" | ||
colors="true" | ||
verbose="true"> | ||
|
||
<php> | ||
<const name="TESTSUITE_CONSUMER_KEY" value="PNVfyHvoowa9h0Tt4fF3VQ"/> | ||
<const name="TESTSUITE_CONSUMER_SECRET" value="rny1vPxJ02H8VSaJCxv3QVVU44Kb41Sy3w7EJHmg"/> | ||
<const name="TESTSUITE_ACCESS_TOKEN" value="14648265-rPn8EJwfBG1FAzGmYUd1YxJB18LJwdEpzlNvEM8SZ"/> | ||
<const name="TESTSUITE_ACCESS_TOKEN_SECRET" value="agvf3L3ebF1vXx8VOmofBZvrJBB1KKIPWfLl5TQLk"/> | ||
<const name="TESTSUITE_CODEBIRD_HOST" value="http://localhost" /> | ||
<const name="TESTSUITE_CODEBIRD_URL" value="/codebird-php" /> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite name="Environment"> | ||
<file>test/environment_test.php</file> | ||
</testsuite> | ||
<testsuite name="Unit"> | ||
<directory suffix="_tests.php">test</directory> | ||
</testsuite> | ||
</testsuites> | ||
<!-- | ||
<logging> | ||
<log type="coverage-html" target="build/coverage" title="codebird-php" | ||
charset="UTF-8" yui="true" highlight="true" | ||
lowUpperBound="35" highLowerBound="70"/> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/> | ||
</logging> | ||
--> | ||
<filter> | ||
<whitelist addUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">.</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
Oops, something went wrong.