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

AccessToken,TicketToken错误回调 #103

Open
shengbeiniao opened this issue Jan 12, 2016 · 3 comments
Open

AccessToken,TicketToken错误回调 #103

shengbeiniao opened this issue Jan 12, 2016 · 3 comments

Comments

@shengbeiniao
Copy link

API文档里,错误回调返回return callback(err),如果更改为return callback(null,null),就可以在accessToken不存在的情况下,调用getAccessToken方法。
cvi _ ol5s3g rc4 b8z8

@shengbeiniao
Copy link
Author

  • var api = new API('appid', 'secret', function (callback) {
    • // 传入一个获取全局token的方法
    • fs.readFile('access_token.txt', 'utf8', function (err, txt) {
    • // if (err) {return callback(err);}
      if (err) {return callback(null,null);}
    • callback(null, JSON.parse(txt));
      
    • });
    • }, function (token, callback) {
    • // 请将token存储到全局,跨进程、跨机器级别的全局,比如写到数据库、redis等
    • // 这样才能在cluster模式及多机情况下使用,以下为写入到文件的示例
    • fs.writeFile('access_token.txt', JSON.stringify(token), callback);
    • });

@JacksonTian
Copy link
Member

这个地方有问题吗? 没有token就需要刷新

@flight9
Copy link

flight9 commented Feb 27, 2018

的确如果按文档写:
if (err) {return callback(err);}
就不会去调用
function (token, callback) {...}
所以永远都不会去缓存这个 token.

改为 if (err) {return callback(null,null);} 就可以,虽然还没读懂,谢谢 @shengbeiniao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants