Hi,
I am using twitter for login in my web application.
While using localhost, the twitter oAuth api to request OAuth token works fine but when i deploy it to a server, it gives an empty object instead of oAuth token.
Hi,
I am using twitter for login in my web application.
While using localhost, the twitter oAuth api to request OAuth token works fine but when i deploy it to a server, it gives an empty object instead of oAuth token.
Thanks for reaching out! Do you have a code sample you can send over on this?
Thanks much for replying @jessicagarson ,
Here is the backend code from which i hit the request oAuth tokn api, followed by the frontend code to call the same.
oauthRouter.route('/:employeeId/:userAccessToken')
.all((req, res, next) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
next();
})
.get((req, res, next) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
var oauth = {
callback: 'https://socialstars.policybazaar.com/social-login'
, consumer_key: '<App_Consumer_key>'
, consumer_secret: '<App_consumer_secret>'
}
var url = 'https://api.twitter.com/oauth/request_token';
users.findOne({ 'employeeId': req.params.employeeId, "authDetails.accessToken": { "$in": req.params.userAccessToken } }).then((doc) => {
if (doc != null) {
request.post({ url: url, oauth: oauth }, function (e, r, body) {
var req_data = qs.parse(body)
res.json(req_data);
})
}
else {
res.json({
"error": true,
"message": "invalid session"
})
}
})
})
frontend code
const path = `/firstStepTwitter/${employeeId}/${token}`;
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
this.http.get(url + path, httpOptions).subscribe((res: any) => {
if (res) {
console.log('request token response =====> ', res);
const oAuthToken = res.oauth_token;
localStorage.setItem('oauthsecret', res.oauth_token_secret);
localStorage.setItem('oauthtoken', res.oauth_token);
this.isLoading = false;
this.authService.loadingListener.next(this.isLoading);
window.open(`https://api.twitter.com/oauth/authenticate?oauth_token=${oAuthToken}`, '_self');
console.log('first step', res);
} else {
this.isLoading = false;
this.authService.loadingListener.next(this.isLoading);
this.toast.showError('Login Failed!');
}
});
Now this works fine on localhost but when i deploy it, the response of request token api is an empty object.
@jessicagarson facing the same issue please look into it
Hello @mappie! Can you share some code?
Iâm posting code of two methods which worked on localhost but did not work on server.
var oauth = { callback: âxxxxxxxxxxxxxxxxxxxxxâ
, consumer_key:âXXXXXâ
, consumer_secret:âXXXXXXâ
} request.post({url:url, oauth:oauth}, function (e, r, body) {
var req_data = qs.parse(body)
res.json(req_data);
})
I tried using twitter node client too even that did not work
var twitter = new Twitter({
âconsumerKeyâ: âxxxxxxxxxxxxxxxxâ,
âconsumerSecretâ: âxxxxxxxxxxxxxxxâ,
âaccessTokenâ: âxxxxxxxxxxxxxxxxxâ,
âaccessTokenSecretâ: âxxxxxxxxxxxxxxxâ,
âcallBackUrlâ: âxxxxxxxxxxxxxxxxxxxxxâ});
twitter.getOAuthRequestToken((error)=>{
res.json({ârâ:error});
},(oauth)=>{
res.json({ârâ:qs.parse(oauth)});
})
@jessicagarson @andypiper please take a look into my code
Thanks for following up here and the code sample. I have a few other follow up questions:
Hi @jessicagarson thanks much for following up,
This is the error response we are getting while hitting the twitter request token endpoint :
{âerrorâ:{âerrnoâ:-104,âcodeâ:âECONNRESETâ,âsyscallâ:âreadâ}}
Have a look at sockets - How do I debug error ECONNRESET in Node.js? - Stack Overflow for clues - this sounds like a networking / connection error on your server.
Try running twurl or something on the server to test if you can successfully connect to twitter API servers from your server, and thereâs nothing blocking requests like a firewall.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.