Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Oauth Error & Works for meteor 0.6.5 & above #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 73 additions & 43 deletions lib/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand All @@ -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
Expand All @@ -31,8 +33,15 @@ 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 = Accounts.twitter._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(){
Expand All @@ -42,59 +51,80 @@ 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.get_credentials = function(credentials) {


var oauthBinding = this.getOauthBinding();
oauthBinding.accessToken=credentials.oauth_token;
oauthBinding.accessTokenSecret = credentials.oauth_secret;
url = 'account/verify_credentials.json';

result = oauthBinding.call('GET',
this._getUrl(url),
{include_entities:true}
);

Twitter.prototype.userTimeline = function() {
return this.get('statuses/user_timeline.json');
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});
};
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});
};
4 changes: 3 additions & 1 deletion package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions smart.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
}
}
}