From dc01356c16b659ea692e68c793c104511d6e9f15 Mon Sep 17 00:00:00 2001 From: Febin John James Date: Mon, 14 Apr 2014 15:09:10 +0530 Subject: [PATCH 1/4] Fixed Oauth Error & Works for meteor 0.6.5 & above --- lib/twitter.js | 10 ++++++++-- package.js | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/twitter.js b/lib/twitter.js index ac9cd76..de943aa 100644 --- a/lib/twitter.js +++ b/lib/twitter.js @@ -31,8 +31,14 @@ Twitter.prototype.call = function(method, url, params){ Twitter.prototype.getOauthBinding = function() { var config = Accounts.loginServiceConfiguration.findOne({service: 'twitter'}); - var urls = Accounts.twitter._urls; - return new OAuth1Binding(config.consumerKey, config.secret, urls); +var urls = { + requestToken: "https://api.twitter.com/oauth/request_token", + authorize: "https://api.twitter.com/oauth/authorize", + accessToken: "https://api.twitter.com/oauth/access_token", + authenticate: "https://api.twitter.com/oauth/authenticate" +}; + + return new OAuth1Binding(config, urls); }; Twitter.prototype.getOauthBindingForCurrentUser = function(){ diff --git a/package.js b/package.js index d1746b8..9e07afa 100644 --- a/package.js +++ b/package.js @@ -6,8 +6,10 @@ Package.on_use(function (api, where) { api.use([ 'accounts-twitter' ], 'server'); - + + api.export && api.export('Twitter', 'server'); api.add_files(['lib/twitter.js'], 'server'); + }); Package.on_test(function (api) { From a0860ea755488f120a51f5016b50341258f24069 Mon Sep 17 00:00:00 2001 From: jamesfebin Date: Tue, 15 Apr 2014 11:39:06 +0530 Subject: [PATCH 2/4] Update smart.json --- smart.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smart.json b/smart.json index 7e1b892..9c30bf5 100644 --- a/smart.json +++ b/smart.json @@ -4,7 +4,7 @@ "homepage": "https://github.com/Sewdn/meteor-twitter-api", "author": "Pieter Soudan", "version": "0.1.0", - "git": "https://github.com/Sewdn/meteor-twitter-api.git", + "git": "https://github.com/jamesfebin/meteor-twitter-api.git", "packages": { } -} \ No newline at end of file +} From 5b9163373a21b75ca2767d2e0b240cfab7658d9b Mon Sep 17 00:00:00 2001 From: Febin John James Date: Sat, 19 Apr 2014 10:25:47 +0530 Subject: [PATCH 3/4] updated twitter --- lib/twitter.js | 78 +++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 42 deletions(-) diff --git a/lib/twitter.js b/lib/twitter.js index de943aa..c797bee 100644 --- a/lib/twitter.js +++ b/lib/twitter.js @@ -13,6 +13,7 @@ Twitter.prototype.get = function(url,params){ }; Twitter.prototype.post = function(url, params){ + console.log(url + " " + params); return this.call('POST',url,params); }; @@ -21,6 +22,7 @@ Twitter.prototype.call = function(method, url, params){ oauthBinding = this.getOauthBindingForCurrentUser(); +console.log(oauthBinding); result = oauthBinding.call(method, this._getUrl(url), params @@ -31,6 +33,7 @@ Twitter.prototype.call = function(method, url, params){ Twitter.prototype.getOauthBinding = function() { var config = Accounts.loginServiceConfiguration.findOne({service: 'twitter'}); + // var urls = Accounts.twitter._urls; var urls = { requestToken: "https://api.twitter.com/oauth/request_token", authorize: "https://api.twitter.com/oauth/authorize", @@ -48,59 +51,50 @@ Twitter.prototype.getOauthBindingForCurrentUser = function(){ oauthBinding.accessToken = user.services.twitter.accessToken; oauthBinding.accessTokenSecret = user.services.twitter.accessTokenSecret; + console.log('oauthBinding is' + oauthBinding); return oauthBinding; }; Twitter.prototype.publicTimeline = function() { - return this.get('statuses/sample.json'); + return this.get('statuses/public_timeline.json'); }; - -Twitter.prototype.userTimeline = function() { - return this.get('statuses/user_timeline.json'); +Twitter.prototype.get_credentials = function(credentials) { + + + var oauthBinding = this.getOauthBinding(); + oauthBinding.accessToken=credentials.oauth_token; + oauthBinding.accessTokenSecret = credentials.oauth_secret; + url = 'oauth/access_token'; + console.log('oauth binding is' + JSON.stringify(oauthBinding)); +result = oauthBinding.call('POST', + this._getUrl(url), + {include_entities:true} + ); +console.log('hack is ' + result); +return result; + }; - Twitter.prototype.postTweet = function(text){ return this.post('statuses/update.json', {status: text}); }; +Twitter.prototype.postReply = function(text,status_id){ -Twitter.prototype.follow = function(screenName){ - return this.post('friendships/create.json',{screen_name: screenName, follow: true}); + tweet = { status: text, in_reply_to_status_id : status_id }; + + console.log(tweet); + return this.post('statuses/update.json', tweet); }; -Twitter.prototype.getLists = function(user) { - if (user) { - return this.get("lists/list.json", { - screen_name: user - }); - } else { - return this.get("lists/list.json"); - } -}; +Twitter.prototype.retweet = function(status_id){ -Twitter.prototype.getListMembers = function(listId, cursor) { - if (cursor === null) { - cursor = "-1"; - } - return this.get("lists/members.json", { - list_id: listId, - cursor: cursor - }); -}; + return this.post('statuses/retweet/'+status_id+'.json'); +} -Twitter.prototype.usersSearch = function(query, page, count, includeEntities) { - if (page === null) { - page = 0; - } - if (count === null) { - count = 10; - } - if (includeEntities === null) { - includeEntities = true; - } - return this.get("users/search.json", { - q: query, - page: page, - count: count, - include_entities: includeEntities - }); -}; +Twitter.prototype.favorite = function(status_id){ + + return this.post('favorites/create.json',{id:status_id}); +} + +Twitter.prototype.follow = function(screenName){ + return this.post('friendships/create.json',{screen_name: screenName, follow: true}); +}; \ No newline at end of file From 328d8099d4ad99ca49c3f30da63a5436959b1845 Mon Sep 17 00:00:00 2001 From: Febin John James Date: Mon, 21 Apr 2014 19:42:12 +0530 Subject: [PATCH 4/4] Added Verify Credentials --- lib/twitter.js | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/lib/twitter.js b/lib/twitter.js index c797bee..1898ef8 100644 --- a/lib/twitter.js +++ b/lib/twitter.js @@ -64,15 +64,45 @@ Twitter.prototype.get_credentials = function(credentials) { var oauthBinding = this.getOauthBinding(); oauthBinding.accessToken=credentials.oauth_token; oauthBinding.accessTokenSecret = credentials.oauth_secret; - url = 'oauth/access_token'; - console.log('oauth binding is' + JSON.stringify(oauthBinding)); -result = oauthBinding.call('POST', + url = 'account/verify_credentials.json'; + +result = oauthBinding.call('GET', this._getUrl(url), {include_entities:true} ); -console.log('hack is ' + result); -return result; + +var servicedata = { + id: result.data.id_str, + screenName: result.data.screen_name, + accessToken: credentials.oauth_token, + accessTokenSecret: credentials.oauth_secret, + profile_image_url : result.data.profile_image_url, + profile_image_url_https: result.data.profile_image_url_https, + lang:result.data.lang + }; + +var twitter_data = { + serviceData: servicedata, + options: { + profile: { + name: result.data.name + } + } +}; + + return Accounts.updateOrCreateUserFromExternalService('twitter', twitter_data.serviceData, twitter_data.options); + + + + +/* +if(result) +return result.data.id_str; +//return JSON.stringify(result); +else +return 'Error'; + */ }; Twitter.prototype.postTweet = function(text){ return this.post('statuses/update.json', {status: text});