How to post a tweet with Meteor.js, Twitter and Oauth

老子叫甜甜 提交于 2019-12-03 17:00:20

The easiest way of doing this: Add the accounts-ui package:

meteor add accounts-ui accounts-twitter

and in your template do

{{loginButtons}}

On the first start of the application, a click on the login button will guide you through the setup process. You will create a Twitter application and copy the consumer key and consumer secret into a form, that meteor presents you. Afterwards you can log in using Twitter.

Make sure to use the latest Meteor version (0.5.2 at this moment)

You can also config your consumer key and secret with code, this is an example with weibo but its work for twitter, google etc... (server side) :

// first, remove configuration entry in case service is already configured
Accounts.loginServiceConfiguration.remove({
    service: "weibo"
});
Accounts.loginServiceConfiguration.insert({
    service: "weibo",
    clientId: "1292962797",
    secret: "75a730b58f5691de5522789070c319bc"
});

You need to add what @Tom31 suggested in your server side, i.e., I have a /server/server.js

Accounts.loginServiceConfiguration.remove({"service": "twitter"});
Accounts.loginServiceConfiguration.insert({
 "service": "twitter",
 "consumerKey" : "<yours>",
 "secret" : "<yours>"
});

Finally, your access token are stored in your user at the database but this information it is not propagated to the client and, if you want to have access to it, you new to create a server side method and access it through Meteor.call or Meteor.apply

Updated: Example of my server side method

I've created my server side method like this:

Meteor.methods({
...
  userGet: function(id) {
   return removeSensibleFields( Meteor.users.findOne({ _id: id }) );
  }
...
});

where removeSensibleFields is a method to remove all unnecessary/private information that may not be sent back to the client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!