问题描述
这是我第一次写Firefox插件。对于我正在编写的插件,我需要致电This is the first time I'm writing a Firefox addon. For the addon I'm trying to write, I need to make calls to Twitter's APIs. In order to do so, I need an oauth library to start off.
I discovered that there already exists such a library in the npm package repository. Seeing how Firefox addons are written in Javascript, I decided to try using it. Unfortunately, it seems that I cannot simply use modules from NodeJS by running npm install oauth
.
Message: Module `crypto` is not found at resource://gre/modules/commonjs/crypto.js
However, is there some other way that I can use these modules, considering it is nonetheless written in Javascript? I am hoping to not have to write an oauth library from scratch just to start my addon.
To clarify, I'm writing addon code, not content script. I want the addon to be the one making the calls to Twitter API.
The code I currently have is pretty simple. I have a class twitter.js
:
var OAuth = require("oauth");
var OAuth2 = OAuth.OAuth2;
var Twitter = function() {
};
module.exports = Twitter;
And in my index.js
I simply add some code to:
var Twitter = require("./twitter");
var twitter = new Twitter();
Fully working Twitter OAuth sign in, using JPM addon sdk:
https://github.com/Noitidart/jpmOAuth/
The dependencies that were needed were the CryptoJS files for the SHA1-HAMC encryption.
Install that addon. It will work perfectly.
When customizing for yourself, you will have to update the global variable gOauth.twitter
entries of callback
, key
, and secret
. You get this from the manage app on twitter:
The details page, this is where you get the key
and callback
- for me the url is - https://apps.twitter.com/app/12197899
Then from the "Keys and Access Tokens" page you get the secret
- for me the url is - https://apps.twitter.com/app/12197899/keys
这篇关于是否有可能使用像“oauth”这样的NodeJS模块?在我的Firefox插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!