Comments (11)
@keshavkaul
In all request is used an "parseAndCheckLogin", so If your cookies expired, all requests throw exception "You are not logged in!"
https://github.com/Schmavery/facebook-chat-api/blob/master/utils.js#L542
from facebook-chat-api.
Yeah I think I will! Here are some ideas I'm gonna go with.
- Allow passing cookie to login along with email and password (email and password is fallback if cookie expires/crumbles)
- Add option to enable storing cookies in a cache (cookiecache.json) so when we login with an email and password, we'll first check the cache for for their email and password
Thoughts?
from facebook-chat-api.
I think this is a good idea. You should check how request
's cookie jars work (they are the same as tough-cookie
).
I think cookie as a string is better than forcing the user to figure out how cookie jars work. It's an implementation detail that they shouldn't have to worry about. The downside is that we have to handle parsing the cookie and checking for errors.
I'm not a huge fan of having this API handle storing the cookies in a jar. We did this for login
before and it was a huge mess because we couldn't handle all the possible ways of load the credentials. I like to think that keeping the API surface as small as possible will guarantee the max power to the user while keeping it usable and maintainable.
I think I'd rather simply have a getter for the cookies (maybe it returns an array of cookies).
What do you think?
from facebook-chat-api.
I guess that way if the user wanted to create a cache of sessions they could do it themselves which is probably better.
So are you still saying we can allow loading a preexisting session? This is my main issue.
from facebook-chat-api.
Yes. I'm saying add two things:
- a setter, potentially just another field inside the object given to login contains a properly formatted string of a cookie. I can't think of a better solution, but a formatted string is very loose in this case. By that I mean that any typo will just make the whole thing throw which kind of sucks, but I'm in favor of simplicity. So I think the format of the string should be the one you get from copy pasting cookies from Chrome (basically the most used way of getting cookies). What do you think @Schmavery?
- a getter, something like
api.getCookies
which would do https://github.com/SalesforceEng/tough-cookie#getcookiessynccurrenturl-options and then map over the array and calltoString
on it
from facebook-chat-api.
This sounds good to me! We'll just wait for some feedback.
from facebook-chat-api.
I've been thinking, we should priorities cookies in the login function. If the cookie fails to login, we can fallback to the users email and password. For example:
login({ cookie: "COOKIE_DATA", email: "FB_EMAIL", password: "FB_PASSWORD" }, function callback (err, api) {
// .. do stuff <3
});
So if the cookie expired, or the session had been ended we would revert back to the email and password.
What're your thoughts on this @bsansouci and @Schmavery?
I'm really in need of this, so I'm going to write this up!
from facebook-chat-api.
I'm fine with this format personally. Login is currently one of the spaghettiest pieces of code left in the project, so we'll have to be careful not to break anything. Thoughts @bsansouci?
from facebook-chat-api.
@markehme don't do a PR, we have some ideas and need to untangle the code a little. The idea would be to serialize the whole app state (including userId, clients, access_token etc..), not just the cookies. Then you can get it with something like api.getAppState
and do fs.writeFile("cache.json", JSON.stringify(api.getAppState()))
before quitting.
Then you would login like
var appState = fs.readFileSync("cache.json", "utf8");
login({ appState: appState, email: "FB_EMAIL", password: "FB_PASSWORD" }, function callback (err, api) {
// .. do stuff <3
});
Do you think that would be enough?
from facebook-chat-api.
That sounds good to me.
from facebook-chat-api.
@Schmavery @bsansouci
Is there anyway to know if cookie login failed due to expired cookies? Do i get an error callback if login by cookie fails? I'm trying to login with only cookies.
from facebook-chat-api.
Related Issues (20)
- chrome extension HOT 1
- How to change Group Thread Name? HOT 1
- Cannot receive "message" from api.listenMQTT when trying to change userAgent HOT 2
- sendMessage can't use param url HOT 1
- api.getThreadList doesn't return page and user url
- Cannot read property 'name' of undefined
- Error 1357005 when setTitle
- how to listen to Message Requests from non-friend accounts? HOT 1
- Rate limit? HOT 1
- esockettimedout HOT 1
- fix login erorr HOT 9
- api.sendMessage is not working now err: 1357005 HOT 2
- The attachment could not be found. HOT 1
- Unexpected token < in JSON at position 0 HOT 11
- Error when use api.listenMQTT (SyntaxError: Unexpected token ↓ in JSON at position 0) HOT 1
- Parse error when use avatar sticker
- Unhandled rejection TypeError: Cannot read properties of undefined (reading 'messageCount') HOT 1
- how do I make the bot wait for a reply HOT 2
- Recieve messages HOT 1
- Issue with Login: Error retrieving userID HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facebook-chat-api.