Hey everyone,
I’ve been working on creating an app using twitters search API. When I attempt to authenticate with twitter, I receive the error in the title and can’t seem to figure out why for the life of me. Here’s my code:
My node serve endpoint
callAuthorize(req: Request, res: Response) {
const header = this.consumerkey + ‘:’ + this.consumersecret;
const encheader = new Buffer(header).toString(‘base64’);
const finalHeader = 'Basic ’ + encheader;
request.post('https://api.twitter.com/oauth2/token', {
form: {'grant_type': 'client_credentials'},
headers: {authorization: finalHeader}
}, function(error, response, body) {
if (error)
console.log(error);
else {
this.bearertoken = JSON.parse(body).access_token;
res.json({success: true, data: this.bearertoken});
}
})
}
My angular 4 service call
searchForHashTags(searchQuery: string): Observable {
const searchTerm = ‘query=’ + searchQuery;
let headers = new Headers();
headers.append('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
return this.httpClient.post(MARKET_SVC_URL + '/twitter/search', searchTerm, {headers: this.headers});
}
if I need to provide any additional code please let me know. I don’t have any additional information on the error as that’s the only response I get from the server. I’ve created an app on the twitter app portal, and am using the consumer key and consumer secret generated their to get access to my Bearer Token.
Thanks everyone for the help 