diff --git a/CHANGELOG b/CHANGELOG index 262e046..51eb546 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,11 @@ codebird-js - changelog ======================= +2.6.0 (2015-04-08) ++ Allow to get the supported API methods as array +- #79 Use POST for users/lookup and statuses/lookup, params may get too long for GET +- #81 Special oauth_ methods: Fix force_login parameter + 2.5.0 (2014-06-23) + #24 Add README section about xAuth + #46 Don't force to send base64 media uploads via proxy diff --git a/README.md b/README.md index 72e16e4..775a8d0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ codebird-js =========== *A Twitter library in JavaScript.* -Copyright (C) 2010-2014 Jublo Solutions +Copyright (C) 2010-2015 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 @@ -272,26 +272,11 @@ cb.__call( ); ``` -### Uploading files to Twitter +### Uploading media to Twitter -The array syntax is obligatory, and the media have to be base64-encoded: +Tweet media can be uploaded in a 2-step process, and the media have to be +base64-encoded. **First** you send each image to Twitter, like this: -```javascript -var params = { - "status": "The bird is flying high. #larry", - "media[]": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB+0lEQVR42mP8//8/Ay0BEwONwagFoxZQDljI0PP8x7/Z93/e+PxXmpMpXp5dh4+ZgYHh0bd/clxYnMuINaMtfvRLgp3RVZwVU+rkuz+eRz+//wXVxcrEkKnEceXTX0dRlhoNTmKDaOvzXwHHv6x9+gtN/M9/hpjTX+GmMzAw/P7HMOnOj+ff//35x/Ds+z9iLfjPwPDt7//QE1/Sz319/RNh3PkPf+58+Yup/t7Xf9p8zFKcTMRa4CLGCrFm1v2fSjs+pJ/7uuvl7w+//yO7HRkUq3GEyrCREMk+kqy2IiyH3/xhYGD48uf/rPs/Z93/yczIwM3CiFU9Hw5xnD4ouvTt4Tf0AP37n+HTb+w+UOBmIs2CICm2R9/+EZlqGRkYzIVYSLMgRIYtUYGdSAsMBFgUuJhIy2iMDAwt2pysjAwLHv78RcgnOcrs5BQVHEyMG579Imi6Nh9zrBxZFgixMW624pXnwldYcTAzLjDhZmUit7AzE2K54c7fp8eF1QhWRobFptwmgiwkF3b//jMwMjJ8+P3/zPs/yx/9Wvr412+MgBJlZ1xsyuOOrbAibMHH3/87b32fce/nR2ypnpuFMVGevU6TQ5SdqKKeEVez5cuf/7te/j727s+9L/++/v3PzcyowM1kIcTiLs7Kz8pIfNnOONouGrVg1AIGAJ6gvN4J6V9GAAAAAElFTkSuQmCC" -); -cb.__call( - "statuses_updateWithMedia", - params, - function (reply) { - // ... - } -); -``` - -#### Multiple images -can be uploaded in a 2-step process. **First** you send each image to Twitter, like this: ```javascript var params = { "media": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB+0lEQVR42mP8//8/Ay0BEwONwagFoxZQDljI0PP8x7/Z93/e+PxXmpMpXp5dh4+ZgYHh0bd/clxYnMuINaMtfvRLgp3RVZwVU+rkuz+eRz+//wXVxcrEkKnEceXTX0dRlhoNTmKDaOvzXwHHv6x9+gtN/M9/hpjTX+GmMzAw/P7HMOnOj+ff//35x/Ds+z9iLfjPwPDt7//QE1/Sz319/RNh3PkPf+58+Yup/t7Xf9p8zFKcTMRa4CLGCrFm1v2fSjs+pJ/7uuvl7w+//yO7HRkUq3GEyrCREMk+kqy2IiyH3/xhYGD48uf/rPs/Z93/yczIwM3CiFU9Hw5xnD4ouvTt4Tf0AP37n+HTb+w+UOBmIs2CICm2R9/+EZlqGRkYzIVYSLMgRIYtUYGdSAsMBFgUuJhIy2iMDAwt2pysjAwLHv78RcgnOcrs5BQVHEyMG579Imi6Nh9zrBxZFgixMW624pXnwldYcTAzLjDhZmUit7AzE2K54c7fp8eF1QhWRobFptwmgiwkF3b//jMwMjJ8+P3/zPs/yx/9Wvr412+MgBJlZ1xsyuOOrbAibMHH3/87b32fce/nR2ypnpuFMVGevU6TQ5SdqKKeEVez5cuf/7te/j727s+9L/++/v3PzcyowM1kIcTiLs7Kz8pIfNnOONouGrVg1AIGAJ6gvN4J6V9GAAAAAElFTkSuQmCC" @@ -303,10 +288,11 @@ cb.__call( // you get a media id back: console.log(reply.media_id_string); - // continue upload of 2nd image here + // continue upload of 2nd image here, if any (just 1 image works, too!) } ); ``` + **Second,** you attach the collected media ids for all images to your call to ```statuses/update```, like this: @@ -323,7 +309,7 @@ cb.__call( ); ``` -More [documentation for tweeting with multiple media](https://dev.twitter.com/docs/api/multiple-media-extended-entities) is available on the Twitter Developer site. +More [documentation for tweeting with media](https://dev.twitter.com/rest/public/uploading-media-multiple-photos) is available on the Twitter Developer site. ### Requests with app-only auth @@ -385,7 +371,7 @@ 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/docs/rate-limiting-faq) +See the [Rate Limiting FAQ](https://dev.twitter.com/rest/public/rate-limiting) for more information. If you allow your callback function to accept a second parameter, diff --git a/bower.json b/bower.json index 895177a..c19e1aa 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "codebird-js", - "version": "2.5.0", + "version": "2.6.0", "homepage": "http://www.jublo.net/projects/codebird/js", "authors": [ "Joshua Atkins ", diff --git a/codebird.js b/codebird.js index 114ac77..baeaddd 100644 --- a/codebird.js +++ b/codebird.js @@ -2,9 +2,9 @@ * A Twitter library in JavaScript * * @package codebird - * @version 2.5.0 + * @version 2.6.0 * @author Jublo Solutions - * @copyright 2010-2014 Jublo Solutions + * @copyright 2010-2015 Jublo Solutions * @license http://opensource.org/licenses/GPL-3.0 GNU Public License 3.0 * @link https://github.com/jublonet/codebird-php */ @@ -135,7 +135,7 @@ var Codebird = function () { /** * The current Codebird version */ - var _version = "2.5.0"; + var _version = "2.6.0"; /** * Sets the OAuth consumer key and secret (App key) @@ -308,6 +308,160 @@ var Codebird = function () { } }; + /** + * Get allowed API methods, sorted by GET or POST + * Watch out for multiple-method "account/settings"! + * + * @return array $apimethods + */ + var getApiMethods = function () { + var httpmethods = { + GET: [ + "account/settings", + "account/verify_credentials", + "application/rate_limit_status", + "blocks/ids", + "blocks/list", + "direct_messages", + "direct_messages/sent", + "direct_messages/show", + "favorites/list", + "followers/ids", + "followers/list", + "friends/ids", + "friends/list", + "friendships/incoming", + "friendships/lookup", + "friendships/lookup", + "friendships/no_retweets/ids", + "friendships/outgoing", + "friendships/show", + "geo/id/:place_id", + "geo/reverse_geocode", + "geo/search", + "geo/similar_places", + "help/configuration", + "help/languages", + "help/privacy", + "help/tos", + "lists/list", + "lists/members", + "lists/members/show", + "lists/memberships", + "lists/ownerships", + "lists/show", + "lists/statuses", + "lists/subscribers", + "lists/subscribers/show", + "lists/subscriptions", + "mutes/users/ids", + "mutes/users/list", + "oauth/authenticate", + "oauth/authorize", + "saved_searches/list", + "saved_searches/show/:id", + "search/tweets", + "statuses/home_timeline", + "statuses/mentions_timeline", + "statuses/oembed", + "statuses/retweeters/ids", + "statuses/retweets/:id", + "statuses/retweets_of_me", + "statuses/show/:id", + "statuses/user_timeline", + "trends/available", + "trends/closest", + "trends/place", + "users/contributees", + "users/contributors", + "users/profile_banner", + "users/search", + "users/show", + "users/suggestions", + "users/suggestions/:slug", + "users/suggestions/:slug/members", + + // Internal + "users/recommendations", + "account/push_destinations/device", + "activity/about_me", + "activity/by_friends", + "statuses/media_timeline", + "timeline/home", + "help/experiments", + "search/typeahead", + "search/universal", + "discover/universal", + "conversation/show", + "statuses/:id/activity/summary", + "account/login_verification_enrollment", + "account/login_verification_request", + "prompts/suggest", + + "beta/timelines/custom/list", + "beta/timelines/timeline", + "beta/timelines/custom/show" + ], + POST: [ + "account/remove_profile_banner", + "account/settings__post", + "account/update_delivery_device", + "account/update_profile", + "account/update_profile_background_image", + "account/update_profile_banner", + "account/update_profile_colors", + "account/update_profile_image", + "blocks/create", + "blocks/destroy", + "direct_messages/destroy", + "direct_messages/new", + "favorites/create", + "favorites/destroy", + "friendships/create", + "friendships/destroy", + "friendships/update", + "lists/create", + "lists/destroy", + "lists/members/create", + "lists/members/create_all", + "lists/members/destroy", + "lists/members/destroy_all", + "lists/subscribers/create", + "lists/subscribers/destroy", + "lists/update", + "media/upload", + "mutes/users/create", + "mutes/users/destroy", + "oauth/access_token", + "oauth/request_token", + "oauth2/invalidate_token", + "oauth2/token", + "saved_searches/create", + "saved_searches/destroy/:id", + "statuses/destroy/:id", + "statuses/lookup", + "statuses/retweet/:id", + "statuses/update", + "statuses/update_with_media", // deprecated, use media/upload + "users/lookup", + "users/report_spam", + + // Internal + "direct_messages/read", + "account/login_verification_enrollment__post", + "push_destinations/enable_login_verification", + "account/login_verification_request__post", + + "beta/timelines/custom/create", + "beta/timelines/custom/update", + "beta/timelines/custom/destroy", + "beta/timelines/custom/add", + "beta/timelines/custom/remove" + ] + }; + return httpmethods; + }; + /** * Main API handler working on any requests you issue * @@ -433,7 +587,7 @@ var Codebird = function () { } var url = _endpoint_oauth + "oauth/authenticate?oauth_token=" + _url(_oauth_token); if (params.force_login === true) { - url += "?force_login=1"; + url += "&force_login=1"; if (params.screen_name !== null) { url += "&screen_name=" + params.screen_name; } @@ -459,7 +613,7 @@ var Codebird = function () { } var url = _endpoint_oauth + "oauth/authorize?oauth_token=" + _url(_oauth_token); if (params.force_login === true) { - url += "?force_login=1"; + url += "&force_login=1"; if (params.screen_name !== null) { url += "&screen_name=" + params.screen_name; } @@ -904,197 +1058,9 @@ var Codebird = function () { break; } - var httpmethods = {}; - httpmethods.GET = [ - // Timelines - "statuses/mentions_timeline", - "statuses/user_timeline", - "statuses/home_timeline", - "statuses/retweets_of_me", - - // Tweets - "statuses/retweets/:id", - "statuses/show/:id", - "statuses/oembed", - "statuses/retweeters/ids", - - // Search - "search/tweets", - - // Direct Messages - "direct_messages", - "direct_messages/sent", - "direct_messages/show", - - // Friends & Followers - "friendships/no_retweets/ids", - "friends/ids", - "followers/ids", - "friendships/lookup", - "friendships/incoming", - "friendships/outgoing", - "friendships/show", - "friends/list", - "followers/list", - "friendships/lookup", - - // Users - "account/settings", - "account/verify_credentials", - "blocks/list", - "blocks/ids", - "users/lookup", - "users/show", - "users/search", - "users/contributees", - "users/contributors", - "users/profile_banner", - "mutes/users/ids", - "mutes/users/list", - - // Suggested Users - "users/suggestions/:slug", - "users/suggestions", - "users/suggestions/:slug/members", - - // Favorites - "favorites/list", - - // Lists - "lists/list", - "lists/statuses", - "lists/memberships", - "lists/subscribers", - "lists/subscribers/show", - "lists/members/show", - "lists/members", - "lists/show", - "lists/subscriptions", - "lists/ownerships", - - // Saved searches - "saved_searches/list", - "saved_searches/show/:id", - - // Places & Geo - "geo/id/:place_id", - "geo/reverse_geocode", - "geo/search", - "geo/similar_places", - - // Trends - "trends/place", - "trends/available", - "trends/closest", - - // OAuth - "oauth/authenticate", - "oauth/authorize", - - // Help - "help/configuration", - "help/languages", - "help/privacy", - "help/tos", - "application/rate_limit_status", - - // Tweets - "statuses/lookup", - - // Internal - "users/recommendations", - "account/push_destinations/device", - "activity/about_me", - "activity/by_friends", - "statuses/media_timeline", - "timeline/home", - "help/experiments", - "search/typeahead", - "search/universal", - "discover/universal", - "conversation/show", - "statuses/:id/activity/summary", - "account/login_verification_enrollment", - "account/login_verification_request", - "prompts/suggest", - - "beta/timelines/custom/list", - "beta/timelines/timeline", - "beta/timelines/custom/show" - ]; - httpmethods.POST = [ - // Tweets - "statuses/destroy/:id", - "statuses/update", - "statuses/retweet/:id", - "statuses/update_with_media", - "media/upload", - - // Direct Messages - "direct_messages/destroy", - "direct_messages/new", - - // Friends & Followers - "friendships/create", - "friendships/destroy", - "friendships/update", - - // Users - "account/settings__post", - "account/update_delivery_device", - "account/update_profile", - "account/update_profile_background_image", - "account/update_profile_colors", - "account/update_profile_image", - "blocks/create", - "blocks/destroy", - "account/update_profile_banner", - "account/remove_profile_banner", - "mutes/users/create", - "mutes/users/destroy", - - // Favorites - "favorites/destroy", - "favorites/create", - - // Lists - "lists/members/destroy", - "lists/subscribers/create", - "lists/subscribers/destroy", - "lists/members/create_all", - "lists/members/create", - "lists/destroy", - "lists/update", - "lists/create", - "lists/members/destroy_all", - - // Saved Searches - "saved_searches/create", - "saved_searches/destroy/:id", - - // Spam Reporting - "users/report_spam", - - // OAuth - "oauth/access_token", - "oauth/request_token", - "oauth2/token", - "oauth2/invalidate_token", - - // Internal - "direct_messages/read", - "account/login_verification_enrollment__post", - "push_destinations/enable_login_verification", - "account/login_verification_request__post", - - "beta/timelines/custom/create", - "beta/timelines/custom/update", - "beta/timelines/custom/destroy", - "beta/timelines/custom/add", - "beta/timelines/custom/remove" - ]; - for (var httpmethod in httpmethods) { - if (httpmethods[httpmethod].indexOf(method) > -1) { + var apimethods = getApiMethods(); + for (var httpmethod in apimethods) { + if (apimethods[httpmethod].indexOf(method) > -1) { return httpmethod; } } @@ -1508,6 +1474,7 @@ var Codebird = function () { setBearerToken: setBearerToken, setUseProxy: setUseProxy, setProxy: setProxy, + getApiMethods: getApiMethods, __call: __call, oauth_authenticate: oauth_authenticate, oauth_authorize: oauth_authorize, diff --git a/package.json b/package.json index d771ce3..9a98048 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codebird", - "version": "2.5.0", + "version": "2.6.0", "description": "A Twitter library in JavaScript.", "keywords": [ "Twitter",