From 9d78f88e76f11b4595f2dc0f3a54ff3a9addbed6 Mon Sep 17 00:00:00 2001 From: "J.M" Date: Fri, 1 Jan 2016 00:00:00 +0000 Subject: [PATCH] Set version to 3.0.0, year to 2016, use https links --- CHANGELOG | 14 +- CONTRIBUTING.md | 2 +- README.md | 624 ++++++++++++++++++------------------ bower.json | 6 +- composer.json | 4 +- src/codebird.php | 8 +- test/codebirdm.php | 4 +- test/codebirdt.php | 4 +- test/constant_tests.php | 4 +- test/curl_tests.php | 8 +- test/detection_tests.php | 4 +- test/environment_test.php | 4 +- test/oauth_tests.php | 4 +- test/replyparse_tests.php | 4 +- test/requestparse_tests.php | 4 +- test/returnformat_tests.php | 4 +- test/setter_tests.php | 4 +- test/signing_tests.php | 4 +- test/singleton_tests.php | 4 +- 19 files changed, 360 insertions(+), 354 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 46e24b6..d1af2ce 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,22 +1,22 @@ codebird-php - changelog ======================== -3.0.0-rc.1 (2015-12-28) -- #107 Decoding issue for big ints on 32-bit servers -+ #32 Add support for streaming API +3.0.0 (2016-01-01) ++ Add unit testing suite ++ #32 Support Twitter Streaming API ++ #144 Support Twitter Collections API ++ #145 Support Twitter TON (Object Nest) API ++ #120 Support Twitter Ads API + #117 Drop cURL workarounds added for PHP 5.3 + Update cacert.pem + #121 Allow for multiple parameters in templated methods by replacing preg_match with preg_match_all + #134 Add support for compressed remote images + #129 Allow to change remote media download timeout -+ #144 Support Collections API -+ #145 Support TON API -+ #120 Support Ads API + Support WebP media format + Fixes for non-multipart media uploads, see #141 + Return rate-limiting info as object, when return format = object -+ Add unit testing suite +- #107 Decoding issue for big ints on 32-bit servers - #147 Undefined index when checking for possible media files 2.7.2 (2015-09-23) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4a7f8be..e6b5c88 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ ### Code style - Please use 2 soft spaces per indent level. - Take a look at the coding style used in codebird.php and apply the same convention to your contributed code. -The styleguide is also available online at http://pear.php.net/manual/en/standards.php. +The styleguide is also available online at https://pear.php.net/manual/en/standards.php. ### License - Code contributed by you will get the same license as Codebird itself, that is, GPU General Public License V3. diff --git a/README.md b/README.md index 40a95dc..0c17980 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ codebird-php ============ -*A Twitter library in PHP.* +*Easy access to the Twitter REST API, Collections API, Streaming API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.* -Copyright (C) 2010-2015 Jublo Solutions +Copyright (C) 2010-2016 Jublo Solutions 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 @@ -17,8 +17,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . -[![Coverage Status](https://img.shields.io/coveralls/jublonet/codebird-php/release%2F3.0.0.svg)](https://coveralls.io/github/jublonet/codebird-php?branch=release%2F3.0.0) -[![Travis Status](https://img.shields.io/travis/jublonet/codebird-php/release%2F3.0.0.svg)](https://travis-ci.org/jublonet/codebird-php/branches) +[![Coverage Status](https://img.shields.io/coveralls/jublonet/codebird-php/master.svg)](https://coveralls.io/github/jublonet/codebird-php?branch=master) +[![Travis Status](https://img.shields.io/travis/jublonet/codebird-php/master.svg)](https://travis-ci.org/jublonet/codebird-php/branches) ### Requirements @@ -29,8 +29,8 @@ along with this program. If not, see . Summary ------- -Use Codebird to connect to the Twitter **REST, Streaming, Collections, TON** -and **Ads API ✨** from your PHP code. +Use Codebird to connect to the Twitter **REST API, Streaming API, Collections API, TON (Object Nest) API** +and **Twitter Ads API** from your PHP code — all using just one library. Codebird supports full 3-way OAuth as well as application-only auth. @@ -42,7 +42,7 @@ To authenticate your API requests on behalf of a certain Twitter user ```php require_once ('codebird.php'); -\Codebird\Codebird::setConsumerKey('YOURKEY', 'YOURSECRET'); // static, see 'Using multiple Codebird instances' +\Codebird\Codebird::setConsumerKey('YOURKEY', 'YOURSECRET'); // static, see README $cb = \Codebird\Codebird::getInstance(); ``` @@ -131,6 +131,28 @@ In this case, you don't need to set the consumer key and secret. For sending an API request with app-only auth, see the ‘Usage examples’ section. +Mapping API methods to Codebird function calls +---------------------------------------------- + +As you can see from the last example, there is a general way how Twitter’s API methods +map to Codebird function calls. The general rules are: + +1. For each slash in a Twitter API method, use an underscore in the Codebird function. + + Example: ```statuses/update``` maps to ```Codebird::statuses_update()```. + +2. For each underscore in a Twitter API method, use camelCase in the Codebird function. + + Example: ```statuses/home_timeline``` maps to ```Codebird::statuses_homeTimeline()```. + +3. For each parameter template in method, use UPPERCASE in the Codebird function. + Also don’t forget to include the parameter in your parameter list. + + 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')`. + Usage examples -------------- @@ -186,7 +208,71 @@ $reply = $cb->users_show($params); This is the [resulting tweet](https://twitter.com/LarryMcTweet/status/482239971399835648) sent with the code above. -### Uploading media to Twitter +### Requests with app-only auth + +To send API requests without an access token for a user (app-only auth), +add a second parameter to your method call, like this: + +```php +$reply = $cb->search_tweets('q=Twitter', true); +``` + +Bear in mind that not all API methods support application-only auth. + + +HTTP methods (GET, POST, DELETE etc.) +------------------------------------- + +Never care about which HTTP method (verb) to use when calling a Twitter API. +Codebird is intelligent enough to find out on its own. + +Response codes +-------------- + +The HTTP response code that the API gave is included in any return values. +You can find it within the return object’s ```httpstatus``` property. + +### Dealing with rate-limits + +Basically, Codebird leaves it up to you to handle Twitter’s rate limit. +The library returns the response HTTP status code, so you can detect rate limits. + +I suggest you to check if the ```$reply->httpstatus``` property is ```400``` +and check with the Twitter API to find out if you are currently being +rate-limited. +See the [Rate Limiting FAQ](https://dev.twitter.com/rest/public/rate-limiting) +for more information. + +Unless your return format is JSON, you will receive rate-limiting details +in the returned data’s ```$reply->rate``` property, +if the Twitter API responds with rate-limiting HTTP headers. + +Return formats +-------------- +The default return format for API calls is a PHP object. +For API methods returning multiple data (like ```statuses/home_timeline```), +you should cast the reply to array, like this: + +```php +$reply = $cb->statuses_homeTimeline(); +$data = (array) $reply; +``` + +Upon your choice, you may also get PHP arrays directly: + +```php +$cb->setReturnFormat(CODEBIRD_RETURNFORMAT_ARRAY); +``` + +The Twitter API natively responds to API calls in JSON (JS Object Notation). +To get a JSON string, set the corresponding return format: + +```php +$cb->setReturnFormat(CODEBIRD_RETURNFORMAT_JSON); +``` + +Uploading images and videos +--------------------------- Twitter will accept the following media types, all of which are supported by Codebird: - PNG @@ -195,6 +281,7 @@ Twitter will accept the following media types, all of which are supported by Cod - WebP - GIF - Animated GIF +- Video Tweet media can be uploaded in a 2-step process: @@ -241,7 +328,7 @@ sent with the code above. More [documentation for uploading media](https://dev.twitter.com/rest/public/uploading-media) is available on the Twitter Developer site. -#### Remote files +### Remote files Remote files received from `http` and `https` servers are supported, too: ```php @@ -259,7 +346,7 @@ you may customise the remote download timeout, like this: $cb->setRemoteDownloadTimeout(10000); // milliseconds ``` -#### Video files +### 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: @@ -326,123 +413,13 @@ $reply = $cb->statuses_update([ ``` -: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), -add a second parameter to your method call, like this: - -```php -$reply = $cb->search_tweets('q=Twitter', true); -``` - -Bear in mind that not all API methods support application-only auth. - -Mapping API methods to Codebird function calls ----------------------------------------------- - -As you can see from the last example, there is a general way how Twitter’s API methods -map to Codebird function calls. The general rules are: - -1. For each slash in a Twitter API method, use an underscore in the Codebird function. - - Example: ```statuses/update``` maps to ```Codebird::statuses_update()```. - -2. For each underscore in a Twitter API method, use camelCase in the Codebird function. - - Example: ```statuses/home_timeline``` maps to ```Codebird::statuses_homeTimeline()```. - -3. For each parameter template in method, use UPPERCASE in the Codebird function. - Also don’t forget to include the parameter in your parameter list. - - 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')`. - -HTTP methods (GET, POST, DELETE etc.) -------------------------------------- - -Never care about which HTTP method (verb) to use when calling a Twitter API. -Codebird is intelligent enough to find out on its own. - -Response codes --------------- - -The HTTP response code that the API gave is included in any return values. -You can find it within the return object’s ```httpstatus``` property. - -### Dealing with rate-limits - -Basically, Codebird leaves it up to you to handle Twitter’s rate limit. -The library returns the response HTTP status code, so you can detect rate limits. - -I suggest you to check if the ```$reply->httpstatus``` property is ```400``` -and check with the Twitter API to find out if you are currently being -rate-limited. -See the [Rate Limiting FAQ](https://dev.twitter.com/rest/public/rate-limiting) -for more information. - -Unless your return format is JSON, you will receive rate-limiting details -in the returned data’s ```$reply->rate``` property, -if the Twitter API responds with rate-limiting HTTP headers. - -Return formats --------------- -The default return format for API calls is a PHP object. -For API methods returning multiple data (like ```statuses/home_timeline```), -you should cast the reply to array, like this: - -```php -$reply = $cb->statuses_homeTimeline(); -$data = (array) $reply; -``` - -Upon your choice, you may also get PHP arrays directly: - -```php -$cb->setReturnFormat(CODEBIRD_RETURNFORMAT_ARRAY); -``` - -The Twitter API natively responds to API calls in JSON (JS Object Notation). -To get a JSON string, set the corresponding return format: - -```php -$cb->setReturnFormat(CODEBIRD_RETURNFORMAT_JSON); -``` - -Using multiple Codebird instances ---------------------------------- - -By default, Codebird works with just one instance. This programming paradigma is -called a *singleton*. - -Getting the main Codebird object is done like this: - -```php -$cb = \Codebird\Codebird::getInstance(); -``` - -If you need to run requests to the Twitter API for multiple users at once, -Codebird supports this as well. Instead of getting the instance like shown above, -create a new object: - -```php -$cb1 = new \Codebird\Codebird; -$cb2 = new \Codebird\Codebird; -``` +**Find more information about [accepted video formats](https://dev.twitter.com/rest/public/uploading-media#videorecs) in the Twitter Developer docs.** -Please note that your OAuth consumer key and secret is shared within -multiple Codebird instances, while the OAuth request and access tokens with their -secrets are *not* shared. +: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 in the [Twitter community forums](https://twittercommunity.com/tags/video). -Consuming the Twitter Streaming API ------------------------------------ +Twitter Streaming API +--------------------- The Streaming APIs give developers low latency access to Twitter’s global stream of Tweet data. A proper implementation of a streaming client will be pushed messages @@ -503,50 +480,234 @@ Find more information on the [Streaming API](https://dev.twitter.com/streaming/o in the developer documentation website. -How Do I…? ----------- +Twitter Collections API +----------------------- -### …access a user’s profile image? +Collections are a type of timeline that you control and can be hand curated +and/or programmed using an API. -First retrieve the user object using +Pay close attention to the differences in how collections are presented — +often they will be decomposed, efficient objects with information about users, +Tweets, and timelines grouped, simplified, and stripped of unnecessary repetition. -```$reply = $cb->users_show("screen_name=$username");``` +Never care about the OAuth signing specialities and the JSON POST body +for POST collections/entries/curate.json. Codebird takes off the work for you +and will always send the correct Content-Type automatically. +Find out more about the [Collections API](https://dev.twitter.com/rest/collections/about) in the Twitter API docs. -with ```$username``` being the username of the account you wish to retrieve the profile image from. +Here’s a sample for adding a tweet using that API method: -Then get the value from the index ```profile_image_url``` or ```profile_image_url_https``` of the user object previously retrieved. +```php +$reply = $cb->collections_entries_curate([ + 'id' => 'custom-672852634622144512', + 'changes' => [ + ['op' => 'add', 'tweet_id' => '672727928262828032'] + ] +]); +var_dump($reply); +``` -For example: +TON (Twitter Object Nest) API +----------------------------- -```$reply['profile_image_url']``` will then return the profile image url without https. +The [TON (Twitter Object Nest) API](https://dev.twitter.com/rest/ton) allows implementers to upload media and various assets to Twitter. +The TON API supports non-resumable and resumable upload methods based on the size of the file. +For files less than 64MB, non-resumable may be used. For files greater than or equal to 64MB, +resumable must be used. Resumable uploads require chunk sizes of less than 64MB. -### …get user ID, screen name and more details about the current user? +For accessing the TON API, please adapt the following code samples for uploading: -When the user returns from the authentication screen, you need to trade -the obtained request token for an access token, using the OAuth verifier. -As discussed in the section ‘Usage example,’ you use a call to -```oauth/access_token``` to do that. +### Single-chunk upload -The API reply to this method call tells you details about the user that just logged in. -These details contain the **user ID** and the **screen name.** +```php +// single-chunk upload -Take a look at the returned data as follows: +$reply = $cb->ton_bucket_BUCKET([ + 'bucket' => 'ta_partner', + 'Content-Type' => 'image/jpeg', + 'media' => $file +]); -``` -stdClass Object -( - [oauth_token] => 14648265-rPn8EJwfB********************** - [oauth_token_secret] => agvf3L3************************** - [user_id] => 14648265 - [screen_name] => jublonet - [httpstatus] => 200 -) +var_dump($reply); + +// use the Location header now... +echo $reply->Location; ``` -If you need to get more details, such as the user’s latest tweet, -you should fetch the complete User Entity. The simplest way to get the +As you see from that sample, Codebird rewrites the special TON API headers into the reply, +so you can easily access them. This also applies to the `X-TON-Min-Chunk-Size` and +`X-Ton-Max-Chunk-Size` for chunked uploads: + +### Multi-chunk upload + +```php +// multi-chunk upload +$file = 'demo-video.mp4'; +$size_bytes = filesize($file); +$fp = fopen($file, 'r'); + +// INIT the upload + +$reply = $cb->__call( + 'ton/bucket/BUCKET?resumable=true', + [[ // note the double square braces when using __call + 'bucket' => 'ta_partner', + 'Content-Type' => 'video/mp4', + 'X-Ton-Content-Type' => 'video/mp4', + 'X-Ton-Content-Length' => $size_bytes + ]] +); + +$target = $reply->Location; +// something like: '/1.1/ton/bucket/ta_partner/SzFxGfAg_Zj.mp4?resumable=true&resumeId=28401873' +$match = []; + +// match the location parts +preg_match('/ton\/bucket\/.+\/(.+)\?resumable=true&resumeId=(\d+)/', $target, $match); +list ($target, $file, $resumeId) = $match; + +// APPEND data to the upload + +$segment_id = 0; + +while (! feof($fp)) { + $chunk = fread($fp, 1048576); // 1MB per chunk for this sample + + // special way to call Codebird for the upload chunks + $reply = $cb->__call( + 'ton/bucket/BUCKET/FILE?resumable=true&resumeId=RESUMEID', + [[ // note the double square braces when using __call + 'bucket' => 'ta_partner', + 'file' => $file, // you get real filename from INIT, see above + 'Content-Type' => 'image/jpeg', + 'Content-Range' => 'bytes ' + . ($segment_id * 1048576) . '-' . strlen($chunk) . '/' . $size_bytes, + 'resumeId' => $resumeId, + 'media' => $chunk + ]] + ); + + $segment_id++; +} + +fclose($fp); +``` + +Twitter Ads API +--------------- + +The [Twitter Ads API](https://dev.twitter.com/ads/overview) allows partners to +integrate with the Twitter advertising platform in their own advertising solutions. +Selected partners have the ability to create custom tools to manage and execute +Twitter Ad campaigns. + +When accessing the Ads API or Ads Sandbox API, access it by prefixing your call +with `ads_`. Watch out for the usual replacements for in-url parameters, +particularly `:account_id`. + +**Tip:** For accessing the Ads Sandbox API, use the `ads_sandbox_` prefix, +like shown further down. + +Here is an example for calling the Twitter Ads API: + +```php +$reply = $cb->ads_accounts_ACCOUNT_ID_cards_appDownload([ + 'account_id' => '123456789', + 'name' => 'Test', + 'app_country_code' => 'DE' +]); +``` + +### Multiple-method API calls + +In the Twitter Ads API, there are multiple methods that can be reached by +HTTP `GET`, `POST`, `PUT` and/or `DELETE`. While Codebird does its best to guess +which HTTP verb you’ll want to use, it’s the safest bet to give a hint yourself, +like this: + +```php +$reply = $cb->ads_sandbox_accounts_ACCOUNT_ID_cards_imageConversation_CARD_ID([ + 'httpmethod' => 'DELETE', + 'account_id' => '123456789', + 'card_id' => '2468013579' +]); +``` + +Codebird will remove the `httpmethod` parameter from the parameters list automatically, +and set the corresponding HTTP verb. + + +How Do I…? +---------- + +### …use multiple Codebird instances? + +By default, Codebird works with just one instance. This programming paradigma is +called a *singleton*. + +Getting the main Codebird object is done like this: + +```php +$cb = \Codebird\Codebird::getInstance(); +``` + +If you need to run requests to the Twitter API for multiple users at once, +Codebird supports this as well. Instead of getting the instance like shown above, +create a new object: + +```php +$cb1 = new \Codebird\Codebird; +$cb2 = new \Codebird\Codebird; +``` + +Please note that your OAuth consumer key and secret is shared within +multiple Codebird instances, while the OAuth request and access tokens with their +secrets are *not* shared. + + +### …access a user’s profile image? + +First retrieve the user object using + +```$reply = $cb->users_show("screen_name=$username");``` + + +with ```$username``` being the username of the account you wish to retrieve the profile image from. + +Then get the value from the index ```profile_image_url``` or ```profile_image_url_https``` of the user object previously retrieved. + + +For example: + +```$reply['profile_image_url']``` will then return the profile image url without https. + +### …get user ID, screen name and more details about the current user? + +When the user returns from the authentication screen, you need to trade +the obtained request token for an access token, using the OAuth verifier. +As discussed in the section ‘Usage example,’ you use a call to +```oauth/access_token``` to do that. + +The API reply to this method call tells you details about the user that just logged in. +These details contain the **user ID** and the **screen name.** + +Take a look at the returned data as follows: + +``` +stdClass Object +( + [oauth_token] => 14648265-rPn8EJwfB********************** + [oauth_token_secret] => agvf3L3************************** + [user_id] => 14648265 + [screen_name] => jublonet + [httpstatus] => 200 +) +``` + +If you need to get more details, such as the user’s latest tweet, +you should fetch the complete User Entity. The simplest way to get the user entity of the currently authenticated user is to use the ```account/verify_credentials``` API method. In Codebird, it works like this: @@ -629,8 +790,8 @@ on twitter.com and use that to complete signing in to the application. ### …know what cacert.pem is for? Connections to the Twitter API are done over a secured SSL connection. -Since 2.4.0, codebird-php checks if the Twitter API server has a valid -SSL certificate. Valid certificates have a correct signature-chain. +Codebird-php checks if the Twitter API server has a valid SSL certificate. +Valid certificates have a correct signature-chain. The cacert.pem file contains a list of all public certificates for root certificate authorities. You can find more information about this file at http://curl.haxx.se/docs/caextract.html. @@ -679,158 +840,3 @@ You may also use an authenticated proxy. Use the following call: $cb->setProxy('', ''); $cb->setProxyAuthentication(':'); ``` - -### …access the Collections API? - -Collections are a type of timeline that you control and can be hand curated -and/or programmed using an API. - -Pay close attention to the differences in how collections are presented — -often they will be decomposed, efficient objects with information about users, -Tweets, and timelines grouped, simplified, and stripped of unnecessary repetition. - -Never care about the OAuth signing specialities and the JSON POST body -for POST collections/entries/curate.json. Codebird takes off the work for you -and will always send the correct Content-Type automatically. - -Find out more about the [Collections API](https://dev.twitter.com/rest/collections/about) in the Twitter API docs. - -Here’s a sample for adding a tweet using that API method: - -```php -$reply = $cb->collections_entries_curate([ - 'id' => 'custom-672852634622144512', - 'changes' => [ - ['op' => 'add', 'tweet_id' => '672727928262828032'] - ] -]); - -var_dump($reply); -``` - -### …access the TON API? - -The [TON (Twitter Object Nest) API](https://dev.twitter.com/rest/ton) allows implementers to upload media and various assets to Twitter. -The TON API supports non-resumable and resumable upload methods based on the size of the file. -For files less than 64MB, non-resumable may be used. For files greater than or equal to 64MB, -resumable must be used. Resumable uploads require chunk sizes of less than 64MB. - -For accessing the TON API, please adapt the following code samples for uploading: - -#### Single-chunk upload - -```php -// single-chunk upload - -$reply = $cb->ton_bucket_BUCKET([ - 'bucket' => 'ta_partner', - 'Content-Type' => 'image/jpeg', - 'media' => $file -]); - -var_dump($reply); - -// use the Location header now... -echo $reply->Location; -``` - -As you see from that sample, Codebird rewrites the special TON API headers into the reply, -so you can easily access them. This also applies to the `X-TON-Min-Chunk-Size` and -`X-Ton-Max-Chunk-Size` for chunked uploads: - -#### Multi-chunk upload - -```php -// multi-chunk upload -$file = 'demo-video.mp4'; -$size_bytes = filesize($file); -$fp = fopen($file, 'r'); - -// INIT the upload - -$reply = $cb->__call( - 'ton/bucket/BUCKET?resumable=true', - [[ // note the double square braces when using __call - 'bucket' => 'ta_partner', - 'Content-Type' => 'video/mp4', - 'X-Ton-Content-Type' => 'video/mp4', - 'X-Ton-Content-Length' => $size_bytes - ]] -); - -$target = $reply->Location; -// something like: '/1.1/ton/bucket/ta_partner/SzFxGfAg_Zj.mp4?resumable=true&resumeId=28401873' -$match = []; - -// match the location parts -preg_match('/ton\/bucket\/.+\/(.+)\?resumable=true&resumeId=(\d+)/', $target, $match); -list ($target, $file, $resumeId) = $match; - -// APPEND data to the upload - -$segment_id = 0; - -while (! feof($fp)) { - $chunk = fread($fp, 1048576); // 1MB per chunk for this sample - - // special way to call Codebird for the upload chunks - $reply = $cb->__call( - 'ton/bucket/BUCKET/FILE?resumable=true&resumeId=RESUMEID', - [[ // note the double square braces when using __call - 'bucket' => 'ta_partner', - 'file' => $file, // you get real filename from INIT, see above - 'Content-Type' => 'image/jpeg', - 'Content-Range' => 'bytes ' - . ($segment_id * 1048576) . '-' . strlen($chunk) . '/' . $size_bytes, - 'resumeId' => $resumeId, - 'media' => $chunk - ]] - ); - - $segment_id++; -} - -fclose($fp); -``` - -### …access the Twitter Ads API? - -The [Twitter Ads API](https://dev.twitter.com/ads/overview) allows partners to -integrate with the Twitter advertising platform in their own advertising solutions. -Selected partners have the ability to create custom tools to manage and execute -Twitter Ad campaigns. - -When accessing the Ads API or Ads Sandbox API, access it by prefixing your call -with `ads_`. Watch out for the usual replacements for in-url parameters, -particularly `:account_id`. - -**Tip:** For accessing the Ads Sandbox API, use the `ads_sandbox_` prefix, -like shown further down. - -Here is an example for calling the Twitter Ads API: - -```php -$reply = $cb->ads_accounts_ACCOUNT_ID_cards_appDownload([ - 'account_id' => '123456789', - 'name' => 'Test', - 'app_country_code' => 'DE' -]); -``` - -#### Multiple-method API calls - -In the Twitter Ads API, there are multiple methods that can be reached by -HTTP `GET`, `POST`, `PUT` and/or `DELETE`. While Codebird does its best to guess -which HTTP verb you’ll want to use, it’s the safest bet to give a hint yourself, -like this: - -```php -$reply = $cb->ads_sandbox_accounts_ACCOUNT_ID_cards_imageConversation_CARD_ID([ - 'httpmethod' => 'DELETE', - 'account_id' => '123456789', - 'card_id' => '2468013579' -]); -``` - -Codebird will remove the `httpmethod` parameter from the parameters list automatically, -and set the corresponding HTTP verb. diff --git a/bower.json b/bower.json index c6400b9..30a368a 100644 --- a/bower.json +++ b/bower.json @@ -1,12 +1,12 @@ { "name": "codebird-php", - "version": "3.0.0-rc.1", - "homepage": "http://www.jublo.net/projects/codebird/php", + "version": "3.0.0", + "homepage": "https://www.jublo.net/projects/codebird/php", "authors": [ "Joshua Atkins ", "J.M. " ], - "description": "A Twitter library in PHP.", + "description": "Easy access to the Twitter REST API, Collections API, Streaming API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.", "main": "src/codebird.php", "moduleType": [], "keywords": [ diff --git a/composer.json b/composer.json index 97bb125..cf43f02 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,12 @@ { "name": "jublonet/codebird-php", - "description" : "A Twitter library in PHP.", + "description" : "Easy access to the Twitter REST API, Collections API, Streaming API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.", "keywords": [ "Twitter", "API", "networking" ], - "homepage": "http://www.jublo.net/projects/codebird/php", + "homepage": "https://www.jublo.net/projects/codebird/php", "license": "GPL-3.0+", "authors": [ { diff --git a/src/codebird.php b/src/codebird.php index 06e252a..abfa0b0 100644 --- a/src/codebird.php +++ b/src/codebird.php @@ -6,10 +6,10 @@ * A Twitter library in PHP. * * @package codebird - * @version 3.0.0-rc.1 + * @version 3.0.0 * @author Jublo Solutions - * @copyright 2010-2015 Jublo Solutions - * @license http://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 + * @copyright 2010-2016 Jublo Solutions + * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 * @link https://github.com/jublonet/codebird-php */ @@ -505,7 +505,7 @@ class Codebird /** * The current Codebird version */ - protected static $_version = '3.0.0-rc.1'; + protected static $_version = '3.0.0'; /** * The Request or access token. Used to sign requests diff --git a/test/codebirdm.php b/test/codebirdm.php index f821e40..e340f21 100644 --- a/test/codebirdm.php +++ b/test/codebirdm.php @@ -8,8 +8,8 @@ * * @package codebird-test * @author Jublo Solutions - * @copyright 2010-2015 Jublo Solutions - * @license http://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 + * @copyright 2010-2016 Jublo Solutions + * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 * @link https://github.com/jublonet/codebird-php */ diff --git a/test/codebirdt.php b/test/codebirdt.php index 67f50dd..dd54dfc 100644 --- a/test/codebirdt.php +++ b/test/codebirdt.php @@ -8,8 +8,8 @@ * * @package codebird-test * @author Jublo Solutions - * @copyright 2010-2015 Jublo Solutions - * @license http://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 + * @copyright 2010-2016 Jublo Solutions + * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 * @link https://github.com/jublonet/codebird-php */ diff --git a/test/constant_tests.php b/test/constant_tests.php index 8935338..b5404a9 100644 --- a/test/constant_tests.php +++ b/test/constant_tests.php @@ -8,8 +8,8 @@ * * @package codebird-test * @author Jublo Solutions - * @copyright 2010-2015 Jublo Solutions - * @license http://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 + * @copyright 2010-2016 Jublo Solutions + * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 * @link https://github.com/jublonet/codebird-php */ diff --git a/test/curl_tests.php b/test/curl_tests.php index c17ed97..71368a0 100644 --- a/test/curl_tests.php +++ b/test/curl_tests.php @@ -8,8 +8,8 @@ * * @package codebird-test * @author Jublo Solutions - * @copyright 2010-2015 Jublo Solutions - * @license http://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 + * @copyright 2010-2016 Jublo Solutions + * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 * @link https://github.com/jublonet/codebird-php */ @@ -38,10 +38,10 @@ protected function getCB() public function testGetCurlInitialization() { $cb = $this->getCB(); - $id = $cb->call('_getCurlInitialization', ['http://test']); + $id = $cb->call('_getCurlInitialization', ['https://test']); $this->assertEquals( [ - 'url' => 'http://test', + 'url' => 'https://test', CURLOPT_RETURNTRANSFER => 1, CURLOPT_FOLLOWLOCATION => 0, CURLOPT_HEADER => 1, diff --git a/test/detection_tests.php b/test/detection_tests.php index c400f57..4ae6e4e 100644 --- a/test/detection_tests.php +++ b/test/detection_tests.php @@ -8,8 +8,8 @@ * * @package codebird-test * @author Jublo Solutions - * @copyright 2010-2015 Jublo Solutions - * @license http://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 + * @copyright 2010-2016 Jublo Solutions + * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 * @link https://github.com/jublonet/codebird-php */ diff --git a/test/environment_test.php b/test/environment_test.php index 59ae5f6..096be65 100644 --- a/test/environment_test.php +++ b/test/environment_test.php @@ -7,8 +7,8 @@ * * @package codebird-test * @author Jublo Solutions - * @copyright 2010-2015 Jublo Solutions - * @license http://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 + * @copyright 2010-2016 Jublo Solutions + * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 * @link https://github.com/jublonet/codebird-php */ diff --git a/test/oauth_tests.php b/test/oauth_tests.php index e20f490..34b10d1 100644 --- a/test/oauth_tests.php +++ b/test/oauth_tests.php @@ -8,8 +8,8 @@ * * @package codebird-test * @author Jublo Solutions - * @copyright 2010-2015 Jublo Solutions - * @license http://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 + * @copyright 2010-2016 Jublo Solutions + * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 * @link https://github.com/jublonet/codebird-php */ diff --git a/test/replyparse_tests.php b/test/replyparse_tests.php index 9d10f84..f1436fd 100644 --- a/test/replyparse_tests.php +++ b/test/replyparse_tests.php @@ -8,8 +8,8 @@ * * @package codebird-test * @author Jublo Solutions - * @copyright 2010-2015 Jublo Solutions - * @license http://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 + * @copyright 2010-2016 Jublo Solutions + * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 * @link https://github.com/jublonet/codebird-php */ diff --git a/test/requestparse_tests.php b/test/requestparse_tests.php index 3ad990b..3de5810 100644 --- a/test/requestparse_tests.php +++ b/test/requestparse_tests.php @@ -8,8 +8,8 @@ * * @package codebird-test * @author Jublo Solutions - * @copyright 2010-2015 Jublo Solutions - * @license http://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 + * @copyright 2010-2016 Jublo Solutions + * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 * @link https://github.com/jublonet/codebird-php */ diff --git a/test/returnformat_tests.php b/test/returnformat_tests.php index 5d735da..3d5a3bd 100644 --- a/test/returnformat_tests.php +++ b/test/returnformat_tests.php @@ -8,8 +8,8 @@ * * @package codebird-test * @author Jublo Solutions - * @copyright 2010-2015 Jublo Solutions - * @license http://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 + * @copyright 2010-2016 Jublo Solutions + * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 * @link https://github.com/jublonet/codebird-php */ diff --git a/test/setter_tests.php b/test/setter_tests.php index dac54f5..80be154 100644 --- a/test/setter_tests.php +++ b/test/setter_tests.php @@ -8,8 +8,8 @@ * * @package codebird-test * @author Jublo Solutions - * @copyright 2010-2015 Jublo Solutions - * @license http://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 + * @copyright 2010-2016 Jublo Solutions + * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 * @link https://github.com/jublonet/codebird-php */ diff --git a/test/signing_tests.php b/test/signing_tests.php index e1b7d07..882964c 100644 --- a/test/signing_tests.php +++ b/test/signing_tests.php @@ -8,8 +8,8 @@ * * @package codebird-test * @author Jublo Solutions - * @copyright 2010-2015 Jublo Solutions - * @license http://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 + * @copyright 2010-2016 Jublo Solutions + * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 * @link https://github.com/jublonet/codebird-php */ diff --git a/test/singleton_tests.php b/test/singleton_tests.php index 9e52bdf..e392c5f 100644 --- a/test/singleton_tests.php +++ b/test/singleton_tests.php @@ -8,8 +8,8 @@ * * @package codebird-test * @author Jublo Solutions - * @copyright 2010-2015 Jublo Solutions - * @license http://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 + * @copyright 2010-2016 Jublo Solutions + * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0 * @link https://github.com/jublonet/codebird-php */